iphone - 调用 PopToRootViewController 后如何清理 View Controller ?
<p><p>我有一个类似于 <a href="https://stackoverflow.com/questions/2920352/poptorootviewcontrolleranimated-and-dealloc-all-views" rel="noreferrer noopener nofollow">this question</a> 的问题但它是特定于 MonoTouch 的。当我需要调用 <code>NavigationController.PopToRootViewController()</code> 时,我目前在堆栈上的第 8 个 ViewController 上,我需要清理一堆东西(引用、事件、图像等)在所有弹出的 ViewController 上,我该怎么做?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>为了实现这一点,我倾向于将 UINavigationController 子类化,以便在 popToRootViewController 发送到父 View 后拦截所有对它的调用。</p>
<p>popToRootViewController 返回一个 NSArray * 包含所有已从堆栈中弹出的 UIViewController,因此您可以向它们发送清理消息。例如:</p>
<pre><code>@interface BCNavigationController : UINavigationController
@end
@implementation BCNavigationController
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated {
NSArray * poppedControllers =;
;
return poppedControllers;
}
- (UIViewController *) popViewControllerAnimated:(BOOL)animated {
UIViewController * poppedController = ;
];
return poppedController;
}
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
NSArray * poppedControllers =;
;
return poppedControllers;
}
- (void) sendPoppedMessageToControllers:(NSArray *)controllers {
for (UIViewController * controller in controllers )
{
if ()
;
}
}
@end
</code></pre>
<p>...然后,在您的 childUIViewController 中</p>
<pre><code>// MyViewController.m
- (void) viewWasPoppedOffStack{
// do some cleanup
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 调用 PopToRootViewController 后如何清理 ViewController ?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/7324233/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/7324233/
</a>
</p>
页:
[1]