UIBarButtonItem 单击后没有反应
从 rootViewController 导航到 UIViewController
if (self.contr == nil) {
ExampleViewController *controller = [[ExampleViewController alloc]
initWithNibName:@"Example"
bundle:[NSBundle mainBundle]];
self.contr = controller;
[controller release];
}
[self.navigationController presentModalViewController:self.contr animated:YES];
方法
-(IBAction) goBack:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
在 UIViewController 中,我有将签名添加到 .h 文件的 。 在 .xib
文件中,我有一个 UIToolbar
和一个 UIBarButtonItem
。我将按钮连接到文件所有者 - goBack
:
所有内容都显示在屏幕中,但是当我单击该按钮时,goBack
不会被调用。我也尝试以编程方式执行此操作,但得到了相同的结果 - 一切都出现了,但对单击没有反应。
有什么想法为什么它不起作用吗?
编辑: 我刚刚发现工具栏上方有一些看不见的东西。如果我单击特定点(在工具栏上),则会调用 goBack: 。由于我使用presentModelViewController导航到此屏幕,因此导航栏没有出现...但可能它就在那里,这就是隐藏工具栏的原因。
From the rootViewController
I navigate to a UIViewController
if (self.contr == nil) {
ExampleViewController *controller = [[ExampleViewController alloc]
initWithNibName:@"Example"
bundle:[NSBundle mainBundle]];
self.contr = controller;
[controller release];
}
[self.navigationController presentModalViewController:self.contr animated:YES];
In the UIViewController I have the method
-(IBAction) goBack:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I added the signature to the .h file.
In the .xib
file, I have a UIToolbar
with a UIBarButtonItem
. I connected the button to the File's Owner - goBack
:
Everything appears in the screen, but when I click on the button, goBack
isn't called. I also tried to do this programatically instead, but I got the same result - everything appears, but no reaction to the click.
Any ideas why it isn't working?
Edit:
I just found out something invisible is over the toolbar. If I click on a specific point (over the toolbar), then goBack: is called. Since I navigated to this screen using presentModelViewController, the navigation bar isn't appearing... but probably it's there and that's what is hiding the tool bar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
已将您的工具栏与文件所有者绑定?
由于您的 UIBarButton 是 UIToolbar 的子视图,因此您必须将 Toolbar 与文件所有者绑定。
Have bind your Toolbar with File Owner?
As your UIBarButton is subview of UIToolbar so you have to bind Toolbar with File Owner.
呈现模态视图控制器不需要您传递
UINavigationController
。我建议您将其更改为:
让我知道这是否有帮助。
Presenting a modal view controller do not require you to pass through a
UINavigationController
. I suggest you to change this:to this:
Let me know if this helps.
在 goBack 方法中尝试一下:
Try this in the goBack method :
如果您没有到达断点,则意味着您没有在 xib 中正确连接它们。
If you are not hitting the breakpoint that means you did not connect them properly in the xib.