简体   繁体   English

InstantiateViewControllerWithIdentifier不会在闭包内部维护实例

[英]instantiateViewControllerWithIdentifier doesn't maintain instance inside closure

I am loading the following code in the main controller. 我正在主控制器中加载以下代码。 I have debugged to assure it is calling the WebPortalViewController with no issues. 我已进行调试,以确保它没有问题地调用WebPortalViewController。

Parent Controller A.viewDidLoad() 父控制器A.viewDidLoad()

    let sponsorViewController:UIViewController = storyboard!.instantiateViewControllerWithIdentifier("Child")   
    childViewController.view.setNeedsLayout()
    childViewController.view.layoutIfNeeded()

The Issue is however that the viewDidLoad function relies on execution of an operation call 但是问题是viewDidLoad函数依赖于操作调用的执行

Child Controller B.viewDidload() 子控制器B.viewDidload()

    let operation = GetActiveSubscriptionOperation()

    operation.getActiveSubscriptionCompletionBlock = { [weak self] (subscription, error) in

      switch (self, subscription, error) {

self is always null until the view Controller is loaded directly from the UITabController. self始终为null,直到直接从UITabController加载视图控制器为止。 How do I get the getActiveSubscriptionCompletionBlock to maintain self in the closure? 如何获取getActiveSubscriptionCompletionBlock来保持self在关闭状态?

weak is declared as an Optional, variable could be nil if not reachable. weak声明为Optional,如果无法访问,则变量可以为nil。 So it is normal getting nil until viewcontroller loaded. 因此,在加载viewcontroller之前,获取nil是正常的。

For me viewDidLoad should not rely on a execution of function it is in lifecycle of viewcontroller. 对我而言,viewDidLoad不应依赖于它在viewcontroller生命周期中执行的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM