iOS 从某个页面返回然后刷新当前页面

时间:2023-03-08 20:10:50

--------》不说废话

在返回页面实现下面方法:

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated;

注意:需要遵循UINavigationControllerDelegate,并使本类成为代理

用法:

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated{

if([[viewController class]isSubclassOfClass:[目标类 class]]) {

//在此执行刷新操作

}

//删除代理,防止该controller销毁后引起navigationController.delegate指向野指针造成崩溃

if(![[viewController class]isSubclassOfClass:[self class]]) {

self.navigationController.delegate=nil;

}

}