我有一个类似于 this question 的问题但它是特定于 MonoTouch 的。当我需要调用 NavigationController.PopToRootViewController()
时,我目前在堆栈上的第 8 个 View Controller 上,我需要清理一堆东西(引用、事件、图像等)在所有弹出的 View Controller 上,我该怎么做?
为了实现这一点,我倾向于将 UINavigationController 子类化,以便在 popToRootViewController 发送到父 View 后拦截所有对它的调用。
popToRootViewController 返回一个 NSArray * 包含所有已从堆栈中弹出的 UIViewController,因此您可以向它们发送清理消息。例如:
@interface BCNavigationController : UINavigationController
@end
@implementation BCNavigationController
- (NSArray *)popToRootViewControllerAnimatedBOOL)animated {
NSArray * poppedControllers = [super popToRootViewControllerAnimated:animated];
[self sendPoppedMessageToControllers:poppedControllers];
return poppedControllers;
}
- (UIViewController *) popViewControllerAnimatedBOOL)animated {
UIViewController * poppedController = [super popViewControllerAnimated:animated];
[self sendPoppedMessageToControllers:[NSArray arrayWithObject:poppedController]];
return poppedController;
}
- (NSArray *)popToViewControllerUIViewController *)viewController animatedBOOL)animated {
NSArray * poppedControllers = [super popToViewController:viewController animated:animated];
[self sendPoppedMessageToControllers:poppedControllers];
return poppedControllers;
}
- (void) sendPoppedMessageToControllersNSArray *)controllers {
for (UIViewController * controller in controllers )
{
if ([controller respondsToSelectorselector(viewWasPoppedOffStack)])
[controller performSelectorselector(viewWasPoppedOffStack)];
}
}
@end
...然后,在您的 child UIViewController 中
// MyViewController.m
- (void) viewWasPoppedOffStack {
// do some cleanup
}
关于iphone - 调用 PopToRootViewController 后如何清理 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7324233/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |