UITextView member variable is always nil in my UIViewController

前端 未结 2 1882
谎友^
谎友^ 2021-01-28 11:25

In my nib, I have a UITextView component.

In my UIViewController I have a UITextView member field and I have used IB to make sure

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 12:24

    I can't see agere you are calling setText, but I think that you try to do it in the initializer. GUI code should not be done before the viewDidLoad in the case of using XIB's or loadView if you make your GUI programatically, or the other viewWill/viewDid... methods.

    The reason is because the views are not loaded before they are actually needed, it is called lazy loading. You should Google that for more info.

提交回复
热议问题