TIM*_*MEX 19 model-view-controller ios swift
当我的孩子执行展开segue时,我的控制器的viewDidAppear被调用.
在这种方法中(仅此方法,我需要知道它是否来自放松)
注意:子节点正在向第一个视图控制器展开,因此这是一个中间视图控制器,而不是真正的根节点.
您应该能够使用以下内容在每个控制器中检测视图控制器的曝光是由于被推/呈现的结果,还是由于弹出/解除/展开而暴露的结果.
这可能或可能足以满足您的需求.
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
// Handle controller being exposed from push/present or pop/dismiss
if (self.isMovingToParentViewController || self.isBeingPresented){
// Controller is being pushed on or presented.
}
else{
// Controller is being shown as result of pop/dismiss/unwind.
}
}
Run Code Online (Sandbox Code Playgroud)
如果你想知道viewDidAppear因为一个unwind segue 而被调用,因为它与传统的pop/dismiss被调用不同,那么你需要添加一些代码来检测是否发生了展开.为此,您可以执行以下操作:
对于您想要纯粹检测到的任何中间控制器,请添加表单的属性:
/** BOOL property which when TRUE indicates an unwind occured. */
@property BOOL unwindSeguePerformed;
Run Code Online (Sandbox Code Playgroud)
然后重写unwind segue方法canPerformUnwindSegueAction:fromViewController:withSender:方法如下:
- (BOOL)canPerformUnwindSegueAction:(SEL)action
fromViewController:(UIViewController *)fromViewController
withSender:(id)sender{
// Set the flag indicating an unwind segue was requested and then return
// that we are not interested in performing the unwind action.
self.unwindSeguePerformed = TRUE;
// We are not interested in performing it, so return NO. The system will
// then continue to look backwards through the view controllers for the
// controller that will handle it.
return NO;
}
Run Code Online (Sandbox Code Playgroud)
现在你有一个标志来检测展开,以及一种在它发生之前检测展开的方法.然后调整viewDidAppear方法以包含此标志.
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
// Handle controller being exposed from push/present or pop/dismiss
// or an unwind
if (self.isMovingToParentViewController || self.isBeingPresented){
// Controller is being pushed on or presented.
// Initialize the unwind segue tracking flag.
self.unwindSeguePerformed = FALSE;
}
else if (self.unwindSeguePerformed){
// Controller is being shown as a result of an unwind segue
}
else{
// Controller is being shown as result of pop/dismiss.
}
}
Run Code Online (Sandbox Code Playgroud)
希望这符合您的要求.
有关处理展开segue链的文档,请参阅:https://developer.apple.com/library/ios/technotes/tn2298/_index.html