-1

I've hidden the navigation bar so I can have a custom UIToolBar up there, but when I set the action property for the toolbar item to a method that pops it, it won't work, and I think it may be because I hid the navigation bar.

Here's my code:

[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Articles" style:UIBarButtonItemStyleBordered target:nil action:@selector(backButtonTapped)]];

...

- (void)backButtonTapped {
    [self.navigationController popViewControllerAnimated:YES];
}

But nothing happens.

4

2 回答 2

3

您的选择器的目标是 nil,而它应该是 self 并且您需要将 sender 参数放在您的操作方法中!

[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Articles" style:UIBarButtonItemStyleBordered target:self action:@selector(backButtonTapped:)]];

-(void) backButtonTapped: (id) sender {
   //code as before here
}

编辑正如@sulthan 所说,不需要sender 参数!你可以像以前一样把它排除在外!

于 2013-04-26T19:24:00.860 回答
0

我在整个视图上有一个 UITapGestureRecognizer,它拦截了 UIBarButton 上的点击。由于这个答案,我解决了这个问题,它基本上从一开始就停止了 UITapGestureRecognizer,除非它在 ​​UIToolBar 之外。

于 2013-04-28T15:20:46.930 回答