与其他许多人一样,我想在UINavigationController中使用“后退”按钮时执行操作。我知道一些替代方法,例如添加我自己的按钮并尝试欺骗外观,使用viewWillDisappear并在所有非后退操作上设置标签,以使视图消失等。UINavigationController子类 - 自定义Pop
但是我想尝试的是继承UINavigationController并在popViewControllerAnimated中注入一些东西:
但我无法获得简单的测试用例。这是我试过的...
我创建了一个新类CustomNavigationController,它继承自UINavigationController。在这里,我更新popViewControllerAnimated:
.H:
#import <UIKit/UIKit.h>
@interface CustomNavigationController : UINavigationController
@end
.M:
#import "CustomNavigationController.h"
@interface CustomNavigationController()
@end
@implementation CustomNavigationController
- (UIViewController *)popViewControllerAnimated:(BOOL)animated{
NSLog(@"pop!");
return [super popViewControllerAnimated:animated];
}
@end
在Interface Builder中,我改变了类导航控制器:
我错过了什么?我希望每当我在这个导航控制器中弹出任何视图时都会记录'pop'。
谢谢 - 我刚刚在一个测试项目中也证实了这一点。我会尽力在其他地方追踪它 – 2012-04-11 18:01:29