問題描述
如何在 init 方法中從 NIB 加載 IBOutlets? (How to load the IBOutlets from NIB in the the init method?)
I need access to the IBOutlets in my initWithNibName method of my UIViewController, but they are all nil as they haven't been instantiated yet. Is there a way to instantiate them? I have read that is not safe to call ‑loadView as it will cause memory leaks. So please tell me if there is any solution.
‑‑‑‑‑
參考解法
方法 1:
Generaly it's not possible, your try to access things that don't even exist in this moment. Why wouldn't you use viewWillAppear() method in this controller? I think it's all that you need. Give us sample of code or something more to work on.
(by Cosmin、Sebastian Łuczak)