开发者

Setting Delegate in awakeFromNib

开发者 https://www.devze.com 2023-04-10 09:46 出处:网络
I have a ViewController in Interface Builder that has a TableViewController embedded in it (I reuse the functionality of the TableViewController elsewhere).I need to set a delegate in the TabelViewCon

I have a ViewController in Interface Builder that has a TableViewController embedded in it (I reuse the functionality of the TableViewController elsewhere). I need to set a delegate in the TabelViewController back to the UIViewController it is embedded in so that I can use the NavigationController of the UIViewController (click on row in embedded TableViewController, new ViewController appears....).

I've got a delegate to make this all work, the only problem I have is where to set the delegate. I had read that awakeFromNib gets called once a nib is read in and all IBOutlets have been set (the embedded TableViewController is an IBOutlet). I can step through the code and see that this function is called when the app first launches. However, when I later c开发者_运维问答all the delegate (when a row is clicked), the delegate is null. If I set the delegate in viewDidLoad, everything works great.

Any ideas why awakeFromNib isn't working? Should I be doing this in viewDidLoad anyway?

Thanks!


You can read more about why your awakeFromNib method is not working properly here: Why won't my awakeFromNib fire?

The viewDidLoad method is a perfect place for setting the UITableViewDelegate no actual benefits from setting it in other methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号