点击后UIBarButtonItem没有反应

时间:2011-06-09 12:47:59

标签: iphone uibarbuttonitem uitoolbar

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

在UIViewController中我有方法

-(IBAction) goBack:(id)sender {
    [self.navigationController dismissModalViewControllerAnimated:YES];
}

我将签名添加到.h文件中。 在.xib文件中,我有UIToolbarUIBarButtonItem。我将按钮连接到文件所有者 - goBack

屏幕上显示所有内容,但是当我点击按钮时,系统不会调用goBack。我也尝试以编程方式执行此操作,但我得到了相同的结果 - 一切都出现了,但没有对点击做出反应。

为什么它不起作用的任何想法?

修改 我刚发现工具栏上有一些看不见的东西。如果我点击特定点(在工具栏上),则调用goBack :.由于我使用presentModelViewController导航到此屏幕,导航栏没有显示...但可能它就在那里,这就是隐藏工具栏的内容。

4 个答案:

答案 0 :(得分:0)

将工具栏与文件所有者绑定?
由于您的UIBarButton是UIToolbar的子视图,因此您必须将工具栏与文件所有者绑定。

答案 1 :(得分:0)

呈现模态视图控制器不需要您通过UINavigationController。我建议你改变这个:

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

到此:

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

如果有帮助,请告诉我。

答案 2 :(得分:0)

在goBack方法中尝试:

  [self.navigationController popToRootViewControllerAnimated:YES];

答案 3 :(得分:0)

如果你没有碰到断点,这意味着你没有在xib中正确连接它们。

相关问题