ios – 在我看来,DidAppear,我怎么知道什么时候被小孩解开?

前端之家收集整理的这篇文章主要介绍了ios – 在我看来,DidAppear,我怎么知道什么时候被小孩解开?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我的孩子执行展开时,我的控制器的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.
    }
}

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

对于任何中间控制器,您只需要检测出来,就可以添加以下形式的属性

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

然后覆盖展开方法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

原文链接:https://www.f2er.com/iOS/337603.html

猜你在找的iOS相关文章