gpt4 book ai didi

ios - 在我的 viewDidAppear 中,我怎么知道它何时被 child 解开?

转载 作者:IT王子 更新时间:2023-10-29 05:14:35 28 4
gpt4 key购买 nike

当我的 child 执行 unwind segue 时,我的 Controller 的 viewDidAppear 被调用。

在这个方法中(只有这个方法,我需要知道它是否来自 unwind)

注意: child 正在展开到第一个 View Controller ,所以这是一个中间 View Controller ,而不是真正的 Root View Controller 。

最佳答案

您应该能够使用以下方法在每个 Controller 中检测 View Controller 的暴露是由于被推送/呈现,还是由于弹出/关闭/展开而暴露。

这可能足以满足您的需求。

- (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.
}
}

如果您想知道 viewDidAppear 是因为展开转场而被调用的,这与调用传统的 pop/dismiss 不同,那么您需要添加一些代码来检测是否发生了展开。为此,您可以执行以下操作:

对于任何你想检测纯粹展开的中间 Controller ,添加一个形式的属性:

/** BOOL property which when TRUE indicates an unwind occured. */
@property BOOL unwindSeguePerformed;

然后覆盖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;
}

现在您有了一个检测解除的标志和一种在解除发生之前检测解除的方法。然后调整 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.
}
}

希望这能满足您的要求。

有关处理展开转场链的文档,请参阅:https://developer.apple.com/library/ios/technotes/tn2298/_index.html

关于ios - 在我的 viewDidAppear 中,我怎么知道它何时被 child 解开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618424/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com