当前位置 : 主页 > 手机开发 > ios >

ios – 在viewDidLoad之前调用prepareForSegue

来源:互联网 收集:自由互联 发布时间:2021-06-11
我试过安装SO和谷歌,但似乎没有人有这个问题. 我的iOS应用程序中有两个ViewControllers. 在viewControllerA上,我调用了一个tap事件: [self performSegueWithIdentifier:@"fooSegue" sender:self]; 这称之为:
我试过安装SO和谷歌,但似乎没有人有这个问题.

我的iOS应用程序中有两个ViewControllers.

在viewControllerA上,我调用了一个tap事件:

[self performSegueWithIdentifier:@"fooSegue" sender:self];

这称之为:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

在viewControllerA上

没问题.

但是那个方法之后,

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

在调用viewDidLoad之前调用viewControllerB.在这个阶段我不需要这个mothod在这个viewController上运行.除此之外,在viewControllerB上调用prepareForSegue之后,viewDidLoad / viewWillApear被调用两次

我试着做一个堆栈strace来看看谁在调用它 – 但这就是我得到的:

* thread #1: tid = 0x5eac3, 0x0001e859 TestApp`-[viewControllerB prepareForSegue:sender:](self=0x0dad98b0, _cmd=0x0188185a, segue=0x0ce9e6f0, sender=0x0dad98b0) + 89 at viewControllerB.m:444, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1   * frame #0: 0x0001e859 TestApp`-[ViewControllerB prepareForSegue:sender:](self=0x0dad98b0, _cmd=0x0188185a, segue=0x0ce9e6f0, sender=0x0dad98b0) + 89 at ViewControllerB.m:444
    frame #1: 0x015f8efa UIKit`-[UIStoryboardSegueTemplate _perform:] + 156
    frame #2: 0x015f8f87 UIKit`-[UIStoryboardSegueTemplate perform:] + 115
    frame #3: 0x011b32e2 UIKit`-[UIViewController loadViewIfRequired] + 605
    frame #4: 0x011b35d9 UIKit`-[UIViewController view] + 35
    frame #5: 0x011cd942 UIKit`-[UINavigationController _startCustomTransition:] + 778
    frame #6: 0x011da8f7 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    frame #7: 0x011db4e9 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 57
    frame #8: 0x0131c0d1 UIKit`-[UILayoutContainerView layoutSubviews] + 213
    frame #9: 0x01103964 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    frame #10: 0x023e682b libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
    frame #11: 0x0286245a QuartzCore`-[CALayer layoutSublayers] + 148
    frame #12: 0x02856244 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380
    frame #13: 0x028560b0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
    frame #14: 0x027bc7fa QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
    frame #15: 0x027bdb85 QuartzCore`CA::Transaction::commit() + 393
    frame #16: 0x0287b5b0 QuartzCore`+[CATransaction flush] + 52
    frame #17: 0x010929bb UIKit`_UIApplicationHandleEventQueue + 13095
    frame #18: 0x02a1e77f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
+ 15
    frame #19: 0x02a1e10b CoreFoundation`__CFRunLoopDoSources0 + 235
    frame #20: 0x02a3b1ae CoreFoundation`__CFRunLoopRun + 910
    frame #21: 0x02a3a9d3 CoreFoundation`CFRunLoopRunSpecific + 467
    frame #22: 0x02a3a7eb CoreFoundation`CFRunLoopRunInMode + 123
    frame #23: 0x04bca5ee GraphicsServices`GSEventRunModal + 192
    frame #24: 0x04bca42b GraphicsServices`GSEventRun + 104
    frame #25: 0x01094f9b UIKit`UIApplicationMain + 1225    
    frame #26: 0x0011112d TestApp`main(argc=1, argv=0xbfffedf8) + 141 at main.m:16

我不知道该怎么做.

任何人都可以在这里投资什么?

如果目标场景具有您通过Interface Builder添加的“容器视图”,其中包含嵌入segue,当您转换到父视图控制器时会自动调用该嵌入segue.此segue将触发子视图控制器及其视图的实例化,此过程最终在父视图控制器上调用prepareForSegue,使其有机会传递子视图控制器可能需要的任何信息(如果有的话).

您应该在目标的父视图控制器以及子视图控制器上看到viewDidLoad,viewDidAppear等.

网友评论