UIBarButtonItem 单击后没有反应

发布于 2024-11-14 10:01:46 字数 1025 浏览 3 评论 0原文

从 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 技术交流群。

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

发布评论

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

评论(4

司马昭之心 2024-11-21 10:01:46

已将您的工具栏与文件所有者绑定?
由于您的 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.

你的笑 2024-11-21 10:01:46

呈现模态视图控制器不需要您传递 UINavigationController。我建议您将其更改

[self.navigationController presentModalViewController:self.contr animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];

为:

[self presentModalViewController:self.contr animated:YES];
[self dismissModalViewControllerAnimated:YES];

让我知道这是否有帮助。

Presenting a modal view controller do not require you to pass through a UINavigationController. I suggest you to change this:

[self.navigationController presentModalViewController:self.contr animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];

to this:

[self presentModalViewController:self.contr animated:YES];
[self dismissModalViewControllerAnimated:YES];

Let me know if this helps.

不气馁 2024-11-21 10:01:46

在 goBack 方法中尝试一下:

  [self.navigationController popToRootViewControllerAnimated:YES];

Try this in the goBack method :

  [self.navigationController popToRootViewControllerAnimated:YES];
赠意 2024-11-21 10:01:46

如果您没有到达断点,则意味着您没有在 xib 中正确连接它们。

If you are not hitting the breakpoint that means you did not connect them properly in the xib.

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