键盘 setInputAccessoryView 按钮未触发
我想在键盘上方显示下一个上一个按钮。我从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的说法是错误的。
使用下面修改后的正确代码。
因为您可能忘记在
goToNextField
中附加冒号(正确的goToNextField:
)。在
goToNextField
的函数实现中,您考虑使用冒号并将:(id) sender
放入函数中。The below statement is wrong.
use the below modified correct code .
Because you might forget to append colon in
goToNextField
(CorrectgoToNextField:
).And in your function implementation for
goToNextField
you were considering the colon and put:(id) sender
in your function.您已经编写了
action:@selector(goToNextField)];
。它应该是action:@selector(goToNextField:)];
You've written
action:@selector(goToNextField)];
. It should beaction:@selector(goToNextField:)];