解决方法
一个快速的解决方案是为viewWilldisappear:方法添加一个实现.一旦viewController响应后退按钮消失就会被触发.
- (void)viewWilldisappear:(BOOL)animated { //... //make you stuff here //... }
另一个解决方案是向后退按钮添加自定义响应器.您可以修改viewController的init方法,如下所示:
- (id)init { if (self = [super init]) { //other your stuff goes here //... //here we customize the target and action for the backBarButtonItem //every navigationController has one of this item automatically configured to pop back self.navigationItem.backBarButtonItem.target = self; self.navigationItem.backBarButtonItem.action = @selector(backButtonDidpressed:); } return self; }
然后可以使用选择器方法如下.请务必正确关闭viewController,否则您的导航控制器将不会按需要弹出.
- (void)backButtonDidpressed:(id)aResponder { //do your stuff //but don't forget to dismiss the viewcontroller [self.navigationController popViewControllerAnimated:TRUE]; }