Iphone 键盘设置InputAccessoryView按钮未启动

Iphone 键盘设置InputAccessoryView按钮未启动,iphone,events,button,keyboard,Iphone,Events,Button,Keyboard,我想在键盘上方显示上一个按钮。我从viewDidLoad调用函数“makeToolBars”来创建它。应用程序确实正确地显示了按钮,但是当我点击按钮时,我得到了一个错误,它没有进入“goToNextField”功能 有人能指出如何纠正它吗 -(void)goToNextField:(id)sender { [txtPassword resignFirstResponder]; [txtUserName becomeFirstResponder]; } -(void) makeT

我想在键盘上方显示上一个按钮。我从viewDidLoad调用函数“makeToolBars”来创建它。应用程序确实正确地显示了按钮,但是当我点击按钮时,我得到了一个错误,它没有进入“goToNextField”功能

有人能指出如何纠正它吗

-(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];


}

下面的说法是错误的

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"Next"
                               style:UIBarButtonItemStyleBordered
                               target:self
                               action:@selector(goToNextField)];
使用下面修改的正确代码

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Next"
                                   style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(goToNextField:)];
因为您可能忘记在
goToNextField
中追加冒号(请更正
goToNextField:


在您的函数实现中,您考虑了冒号并将
:(id)sender
放在函数中。

下面的语句是错误的

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"Next"
                               style:UIBarButtonItemStyleBordered
                               target:self
                               action:@selector(goToNextField)];
使用下面修改的正确代码

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Next"
                                   style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(goToNextField:)];
因为您可能忘记在
goToNextField
中追加冒号(请更正
goToNextField:


在您对
goToNextField
的函数实现中,您考虑了冒号,并将
:(id)sender
放在函数中。

您已经编写了
操作:@selector(goToNextField)]。它应该是
action:@selector(goToNextField:)]

您已经编写了
操作:@selector(goToNextField)]。它应该是
action:@selector(goToNextField:)]