键盘 setInputAccessoryView 按钮未触发

发布于 2024-11-10 09:04:34 字数 1132 浏览 3 评论 0原文

我想在键盘上方显示下一个上一个按钮。我从 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];


}

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


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见 2024-11-17 09:04:34

下面的说法是错误的。

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 放入函数中。

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.

梦醒灬来后我 2024-11-17 09:04:34

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

You've written action:@selector(goToNextField)];. It should be action:@selector(goToNextField:)];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文