I'm simply trying to assign a UITextField.text to an NSString in my object. The code errors out when I try to print the enteredLocation.text but I have no idea why. I thought it was a type mismatch, but both are NSString. Any idea?
- (IBAction) submitPushed: (UITextField*)enteredName: (UITextField*)enteredCell: (UITextField*)enteredLocation;
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
NSLog(@"LOC %@", enteredLocation.text);
theDataObject.location = enteredLocation.text;
NSLog(@"DATAOBJ %@", theDataObject.location);
}
I always get this error:
2011-08-20 10:28:13.602 ViewControllerDataSharing[3188:207] -[UITouchesEvent text]: unrecognized selector sent to instance 0x4e07780
2011-08-20 10:28:13.607 ViewControllerDataSharing[3188:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITouchesEvent text]: unrecognized selector sent to instance 0x4e07780'
But UITouchEvent? How does that relate? I ctrl-clicked the button to the method in my .m file. Is there a step missing? I tried checking if the text is "", but it won't even get th开发者_运维技巧at far.
I have the I'm a major newbie, so thanks in advance. I've read 100s of answers on this site, and love it!! So helpful!
THANKS! Mark
When the action fires for your button, the method signature will look like one of these:
-(IBACtion)onPushed; // no parameters
-(IBAction)onPushed:(id)sender; // sender is the control that initiated the event
-(IBAction)onPushed:(id)sender event:(UITouchesEvent*)event; // event is the touch event that caused the event
You can't control what gets passed to your handler by changing the parameters. If you need to access the text field, make sure there is an IBOutlet reference to the UITextField object in your class (and hook it up in IB) and use that to access it.
I'm guessing that you have the IBAction hooked up to the wrong action in your nib - one that is a touch event. If you try:
NSLog(@"Param1: %@", enterdLocation);
You'll see that the method is being passed a UITouchesEvent object instead of a UITextField object.
Double-check your nib connections.
精彩评论