我知道这将是一件非常愚蠢的事情,但我现在已经试图解决这两天了,所以我承认失败了。
我正在尝试在NavBar上实现Double Tap Gesture识别器。然而,当双击它时,我得到以下崩溃......
2014-10-11 13:05:01.317 Gesture[4811:152609] -[UINavigationBar navigationBarDoubleTap:]: unrecognized selector sent to instance 0x78818150
2014-10-11 13:05:01.321 Gesture[4811:152609] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationBar navigationBarDoubleTap:]: unrecognized selector sent to instance 0x78818150'
它是一个普通的视图控制器,在视图中添加了一个导航栏。我在ViewDidLoad中实例化了手势识别器......
.h
IBOutlet UINavigationBar *navBar;
UITapGestureRecognizer *tapRecon;
.m (viewDidLoad)
//Add double tap gesture to Navbar For Auto Refresh
tapRecon = [[UITapGestureRecognizer alloc]
initWithTarget:navBar action:@selector(navigationBarDoubleTap:)];
tapRecon.numberOfTapsRequired = 2;
[navBar addGestureRecognizer:tapRecon];
DoubleTap方法是
(void)navigationBarDoubleTap :(id) sender {
NSLog(@"Sender: %@", sender);
}
我已将navBar连接到我的UINavigationBar,并将其委托设置为View。我也尝试过使用和不使用(id)发件人的方法。
非常感谢
血浆
答案 0 :(得分:2)
tapRecon = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(navigationBarDoubleTap:)];
tapRecon.numberOfTapsRequired = 2;
[navBar addGestureRecognizer:tapRecon];