UIBarButtonItem not reacting after click

前提是你 提交于 2019-12-25 10:03:33

问题


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.


回答1:


Have bind your Toolbar with File Owner?
As your UIBarButton is subview of UIToolbar so you have to bind Toolbar with File Owner.




回答2:


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.




回答3:


Try this in the goBack method :

  [self.navigationController popToRootViewControllerAnimated:YES];



回答4:


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



来源:https://stackoverflow.com/questions/6445170/uibarbuttonitem-not-reacting-to-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!