从 instantiateViewControllerWithIdentifier 加载 UIViewController - nil 插座 [英] Loading UIViewController from instantiateViewControllerWithIdentifier - nil outlets

查看:31
本文介绍了从 instantiateViewControllerWithIdentifier 加载 UIViewController - nil 插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老实说,我无法理解我做错了什么.

I honestly can't understand what am i doing wrong.

我有这个 UIViewController 的共享实例:

I have this shared Instance of my UIViewController :

static let sharedInstance = UIStoryboard(name:"Main", bundle:nil).instantiateViewControllerWithIdentifier("IAPNEW") as! newIAPClass

如果我正在展示它,而没有访问它的出口,那么:

If i'm presenting it, without accessing it outlets, as so :

 self.presentViewController(newIAPClass.sharedInstance, animated: true, completion: nil)

它按预期工作(出现).但是 - 如果我试图访问他的网点,它会因found nil"错误而崩溃:

It's works as expected(show's up). BUT - if i'm trying to access his outlets, it's crashing with "found nil" error :

        newIAPClass.sharedInstance.lbl_full.text = "mMM"
        self.presentViewController(newIAPClass.sharedInstance, animated: true, completion: nil) 

有人知道为什么网点为零吗?

推荐答案

最初没有设置网点.处理此问题的标准方法是将数据存储在属性中,然后将该数据移动到 viewDidLoad 中的插座中.

The outlets aren't set up initially. The standard way to deal with this is to store your data in properties and then move that data into your outlets in viewDidLoad.

因为您是在单例中加载它,所以 viewDidLoad 只会被调用一次.相反,将数据从您的属性复制到 viewWillAppear 中的插座.

Since you are loading this in a Singleton, viewDidLoad will only be called once. Instead, copy your data from your properties to your outlets in viewWillAppear.

这篇关于从 instantiateViewControllerWithIdentifier 加载 UIViewController - nil 插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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