问题描述
相信大家都会遇到过这种情况:
进入下一页面,并且在下一页面执行某一动作,返回要刷新,没有执行某一动作,返回不刷新。也就是当前页面要实现按照需求刷新页面
实现思路
在当前页面定义个Bool类型属性 isNeedRefresh,在viewWillAppear中进行判断是否需要刷新。在第二页面中重写返回按钮。
通过 self.navigationController.viewControllers来获取上衣页面的ctl
实现代码
当前viewcontroller
@property (nonatomic, assign) BOOL isNeedRefresh;//是否需要刷新 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (self.isNeedRefresh) { NSLog(@"执行刷新了"); [self loadData]; } }
#pragma mark 重写返回按钮 - (void)LeftBtnClicked:(UIButton *)sender{ [self.view endEditing:YES]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; UIViewController *ctl = self.navigationController.viewControllers[self.navigationController.viewControllers.count - 2]; if ([ctl isKindOfClass:[AddServiceViewController class]]) { AddServiceViewController * ctl2 = (AddServiceViewController*)ctl; ctl2.isNeedRefresh = YES; [self.navigationController popToViewController:ctl2 animated:YES]; }else{ [self.navigationController popViewControllerAnimated:YES]; } }