keyboard setInputAccessoryView buttons not firing
I want to show next previous buttons above the keyboard. I call function "makeToolBars" from viewDidLoad to create it. The application does display the buttons correctly but when I click on them I get error it does not go to "goToNextField" function.
开发者_如何学编程Can anyone point how to correct it ?
-(void)goToNextField:(id)sender
{
[txtPassword resignFirstResponder];
[txtUserName becomeFirstResponder];
}
-(void) makeToolBars
{
UIToolbar *toolbar1 = [[[UIToolbar alloc] init] autorelease];
[toolbar1 setBarStyle:UIBarStyleBlackTranslucent];
[toolbar1 sizeToFit];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
initWithTitle:@"Next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(goToNextField)];
UIBarButtonItem *flexButton1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
NSArray *itemsArray1 = [NSArray arrayWithObjects: nextButton,flexButton1, nil];
[flexButton1 release];
[nextButton release];
[toolbar1 setItems:itemsArray1];
[txtUserName setInputAccessoryView:toolbar1];
}
The below statement is wrong.
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
initWithTitle:@"Next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(goToNextField)];
use the below modified correct code .
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
initWithTitle:@"Next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(goToNextField:)];
Because you might forget to append colon in goToNextField
(Correct goToNextField:
).
And in your function implementation for goToNextField
you were considering the colon and put :(id) sender
in your function.
You've written action:@selector(goToNextField)];
. It should be action:@selector(goToNextField:)];
精彩评论