Get outlet size within awakeFromNib

巧了我就是萌 提交于 2019-12-01 17:41:01
Guillaume Algis

A part of the answer is in dreamzor's response to iOS AutoLayout - get frame size width.

The trick is to place your frame-dependent code to the viewDidLayoutSubviews method

In my particular case, I found that adding [self layoutIfNeeded]; in my custom cell awakeFromNib method, right before asking for the outlet size worked like a charm.

I am not sure if this is the optimal solution but to make some changes on subviews or getting information like you do, I create a method on the subview like "prepareSubviews" or "refresh" or "populateWithData". After initializing/ loading view from IB, I invoke that method inside "viewDidLoad", at that point the xib file should be loaded and working properly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!