performSegueWithIdentifier 的调用顺序 [英] Order of Calls on performSegueWithIdentifier

查看:21
本文介绍了performSegueWithIdentifier 的调用顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用 performSegueWithIdentifier: 之后,我将覆盖 prepareForSegue: 以便在我的目标视图控制器上设置一些属性.但是,我试图了解这里的操作顺序以确保它是安全的.

When I call performSegueWithIdentifier: I am overriding prepareForSegue: afterwards in order to set some properties on my destination view controller. However, I'm trying to understand the order of operations here to make sure it's safe.

我使用以下命令实例化目标视图控制器:

I instantiate the destination view controller with:

MyViewController *myVC = (MyViewController*)segue.destinationViewController;

之后,我在其上设置了一些属性 - 即,我初始化另一个处理加载不同 Web 视图的对象的创建,然后在该对象上设置属性:

Afterwards I set a few properties on it - namely, I initialize the creation of another object which handles loading different web views, and then set properties on that object:

[myVC setFormHandler:
    [[WebFormHandler alloc] initWithSelectedFormName:[self theFormName]]];

在目标控制器的 viewDidLoad: 中,然后查询此对象的属性,并使用它加载正确的 Web 视图.现在,我对哪个先发生感到有些困惑 - 属性的设置,或目标控制器上的 viewDidLoad:.是否可以肯定地说,在调用 viewDidLoad: 之前,视图控制器的属性总是会从 prepareForSegue: 设置?

In viewDidLoad: of my destination controller, I then query the properties on this object, and use this to load the correct web view. Now, I am slightly confused by which happens first - the setting of the properties, or viewDidLoad: on the destination controller. Can it be said for certain that the properties of the view controller will always be set from prepareForSegue: before the viewDidLoad: is called?

推荐答案

看起来您可能已经从其他帖子中找到了答案,但我只想补充一点说明.

It looks like you may have found your answer from that other post, but I just wanted to add one point of clarification.

标准流程是

performSegue -> prepare -> loadView(在目标控制器中)

performSegue -> prepare -> loadView (in destination controller)

但是,在 popover segue 中,目标视图在 prepareForSegue 调用之前加载.

However, in popover segues, the destination view is loaded prior to the prepareForSegue call.

注意:在 iOS 8 中不再是这种情况.在 iOS 8 中,在调用 prepareForSegue 时不会加载 popover segue 的视图.

NOTE: This is no longer the case in iOS 8. In iOS 8, popover segue's views are NOT loaded by the time prepareForSegue is called.

这篇关于performSegueWithIdentifier 的调用顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆