Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 15, 2012, 03:25 PM   #1
kikko088
macrumors member
 
Join Date: Oct 2010
Location: Italy
Passing String with Notification and than pass to class

I have a question I work for an ipad application, in this app on main view I have an instance of a custom uitableviewcontroller, on row click I post a notification that pass an object and run a method

Code:
- (void) drawWebView:(id) sender {

    NSDictionary *dict = [[sender userInfo] copy];
    self.objTesto = [dict objectForKey:@"Testo"];
    self.txtWeb = self.objTesto.testo;

    //[self setWebView:self.txtWeb];
    [self.textWebView loadRequest:[self creaFileHTML:text]];
}
while I set the load request on the webview of my class all work, If I creat a subclass of uiwebview with a method setWebView: whit a simple NSLog()

Code:
[self setWebView:self.txtWeb];
//[self.textWebView loadRequest:[self creaFileHTML:text]];
I get this error:

Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString userInfo]: unrecognized selector sent to instance 0xee3a1e0'
__________________
iTouch 1G
kikko088 is offline   0 Reply With Quote
Old Nov 15, 2012, 04:02 PM   #2
Reason077
macrumors 65816
 
Join Date: Aug 2007
Quote:
Originally Posted by kikko088 View Post
I have a question I work for an ipad application, in this app on main view I have an instance of a custom uitableviewcontroller, on row click I post a notification that pass an object and run a method

Code:
- (void) drawWebView:(id) sender {
    NSDictionary *dict = [[sender userInfo] copy];
What class do you expect "sender" to be at this point? Obviously not an NSString, but it looks like that's what it is. NSString has no "userInfo" method, and that's why it crashes.

It's usually a bad idea to declare a method paramater as the "id" type, because you lose type safety.
Reason077 is offline   0 Reply With Quote
Old Nov 15, 2012, 04:22 PM   #3
kikko088
Thread Starter
macrumors member
 
Join Date: Oct 2010
Location: Italy
the sender is an object, here I get the string:

Code:
self.objTesto = [dict objectForKey:@"Testo"];
self.txtWeb = self.objTesto.testo;

I think, if I use it without an external class all work.
__________________
iTouch 1G
kikko088 is offline   0 Reply With Quote
Old Nov 15, 2012, 05:22 PM   #4
kikko088
Thread Starter
macrumors member
 
Join Date: Oct 2010
Location: Italy
the problem was that I init the wrong class (I have two similar class) - stupid error -.- excuse me!
__________________
iTouch 1G
kikko088 is offline   0 Reply With Quote
Old Nov 16, 2012, 04:19 AM   #5
Reason077
macrumors 65816
 
Join Date: Aug 2007
Quote:
Originally Posted by kikko088 View Post
the problem was that I init the wrong class (I have two similar class) - stupid error -.- excuse me!
That's why you should avoid declaring variables and parameters as type "id". These sorts of errors would get picked up by the compiler, instead of causing crashes at runtime!
Reason077 is offline   0 Reply With Quote
Old Nov 16, 2012, 08:22 AM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
I just wanted to say that it is pretty common for the sender parameter of an IBAction to be data-typed as an id.
__________________
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Match string against regex or character class in Applescript urello Mac Programming 0 Mar 7, 2014 06:11 AM
Format string is not a string literal. larswik Mac Programming 5 Jan 17, 2014 10:45 PM
Search a string for a String of a specific format. ncaissie iPhone/iPad Programming 19 Nov 15, 2013 10:42 AM
Referencing a child class in a parent class, good or bad? SAIRUS iPhone/iPad Programming 11 Aug 28, 2013 11:59 AM
Passing a string(in user mode) to kernel kext(kext have a dynamic buffer) mehdies Mac Programming 0 Apr 28, 2013 01:22 AM

Forum Jump

All times are GMT -5. The time now is 01:26 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC