我希望在导航控制器堆栈中的视图控制器弹出或推入时收到通知。 我尝试使用
- (void)setViewControllers:(NSArray *)viewControllers
但我失败了。 而且我不想使用委托方法来实现这个...
我希望在导航控制器堆栈中的视图控制器弹出或推入时收到通知。 我尝试使用
- (void)setViewControllers:(NSArray *)viewControllers
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"poped" object:nil userInfo:@{}];
return [super popToRootViewControllerAnimated:animated];
}
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"poped" object:nil userInfo:@{}];
return [super popToViewController:viewController animated:animated];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"poped" object:nil userInfo:@{}];
return [super popViewControllerAnimated:animated];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushed" object:nil userInfo:@{}];
return [super pushViewController:viewController animated:animated];
}
nil
发布通知通常是不好的做法。在这种情况下,您将无法区分事件是发生在导航 VC 中还是在另一个选项卡中,或者可能是在模态窗口中。经验法则是始终代表特定对象发布通知,并始终订阅代表特定对象发布的通知。 - kjam- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated