开发者

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:)];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜