由于一个奇怪的请求,我试图拒绝,但它没有工作,我不得不覆盖navigationBar的后退按钮.
我已经制作了一个自定义的UINavigationController子类并且破解了该
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item方法.
这是我的代码:
@interface CustomUINavigationController ()
@end
@implementation CustomUINavigationController
#pragma mark - UINavigationBar delegate methods
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
if ([[self.viewControllers lastObject] isKindOfClass:[ViewController1 class]]) {
ViewController1 *vc1 = (ViewController1 *)[self.viewControllers lastObject];
[vc1 handleBackAction];
if (vc1.canPopVC == YES) {
[self popViewControllerAnimated:YES];
return YES;
} else {
return NO;
}
}
[self popViewControllerAnimated:YES];
return YES;
}
@end
Run Code Online (Sandbox Code Playgroud)
一切正常,除非我以编程方式弹出viewController.每次我想在弹出后执行推送时,应用程序都会崩溃.转向NSZombie on,显示当以编程方式弹出viewController时,其父viewController被释放.此时,制作自定义backButton不是一个选项,因为它将丢失原生iOS 7滑动到popViewController功能.
崩溃日志:
*** -[ContactsDetailViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x1806b790
Run Code Online (Sandbox Code Playgroud)