【发布时间】:2013-10-01 05:27:50
【问题描述】:
我正在尝试使用以下代码集禁用视图控制器的后退手势。
在FirstViewController.m 中,我正在设置interactivePopGestureRecognizer 的代表
- (void) viewWillLoad {
// Other stuff..
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
然后实现<UIGestureRecognizerDelegate>方法并返回NO。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return NO;
}
在 dealloc 中,我将委托设置为 nil。 (我在某处读到,在 iOS 7 中,您必须手动将代表设置为 nil)
- (void)dealloc {
self.navigationController.delegate = nil;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
这适用于FirstViewController。但是当我将SecondViewController 推到这里时,手势也不起作用。如何仅在 FirstViewController 中禁用手势?
另外,当我弹出FirstViewController 以转到RootViewController,然后再次尝试推送FirstViewController 时,我得到对象释放错误:
[FirstViewController gestureRecognizer:shouldReceiveTouch:]: message sent to deallocated instance 0x14ed0280
除了将代表设置为 nil 之外,我还需要做什么?还是我放错地方了?
【问题讨论】: