何时/如何-出口-> didSet [英] When/How - Outlet -> didSet

查看:132
本文介绍了何时/如何-出口-> didSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,插座上的didSet何时/如何触发?

I'm wondering, when/how does the didSet on an outlet actually trigger?

例如:

   @IBOutlet weak var modifyButton: UIButton! {
    didSet {
        modifyButton.layer.cornerRadius = 9
    }
}

推荐答案

刚刚初始化类时,插座属性初始化为nil.当从nib初始化对象时,它们将具有稍后的值.可以确定所有正确配置的插座属性的值为nil的第一步是viewDidLoad.因此,将在viewDidLoad之前调用此属性的didSet观察者.因为所有这些,您需要注意插座属性:例如,如果尝试使用prepareForSegue方法

Outlet properties initialized as nil when class just initialized. They will have values later, when objects will be initialized from nib. First step, when you can be sure that all properly configured outlet properties have nonnil values is viewDidLoad. So, didSet observer on this properties will be called just before viewDidLoad. Because all of this you need to be careful with outlet properties: for example you will receive nil if you will try access them in prepareForSegue method

这篇关于何时/如何-出口-> didSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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