crash in textFieldShouldReturn

Precisely I am having this error

[<MyViewController> _clearBecomeFirstResponderWhenCapable] -- NSInvalidArgumentException Unrecognized selector sent to instance

What is _clearBecomeFirstResponder?

I am creating a couple of views manually in my viewcontroller - On the similar lines of UICatalog. I create a text field and set my view controller as delegate.

Here's the code

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

// setup our parent content view and embed it to your view controller
UIView *contentView = [[UIView alloc] initWithFrame:screenRect];
contentView.backgroundColor = [UIColor colorWithRed:.56 green:.071 blue:.067 alpha:1];//[UIColor blackColor];
//loginTableView.backgroundColor = [UIColor colorWithRed:.56 green:.071 blue:.067 alpha:1];

contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

self.view = contentView;
[contentView release];

// create the UITextField

refTextField = [[UITextField alloc] initWithFrame:textFrame];

// set the various properties here
.....
// now add the text field to the view

[self.view addSubview:refTextField];
refTextField.delegate = self;


Is there something I am missing? I've set the proper delegate and implemented this protocol method

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ( textField == refTextField ) {
NSLog(@"came to delegate method for UITextFieldDelegate");
[self resignFirstResponder];
}
return YES;
}

But when I click the return button, the above error comes.

Thanks in advance.

iMac, Mac OS X (10.5.4)

Posted on Sep 23, 2008 1:06 AM

Reply
3 replies

Sep 23, 2008 2:37 AM in response to TheCubanPrincess

I troubleshooted with it a while.
I added a target action as described in the UITextFieldDelegate protocol reference
for textFieldShouldReturn

-init{
[refTextField addTarget:self action:@selector(OnTextChange) forControlEvents:UIControlEventEditingDidEndOnExit];

}

I also tried to add the delegate in the ViewDidLoad method. But still no luck. I think I am missing something fundamental here. I am yet to read the UIResponder and events thoroughly. May be that will help? 🙂

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

crash in textFieldShouldReturn

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.