开发者

Setting NSView default property value based on initial bounds

开发者 https://www.devze.com 2023-04-02 11:31 出处:网络
I need to set a property of an NSView loaded from a Nib calculated using its initial bounds. Its bounds is still null inside - (void)awakeFromNib, so what is the first开发者_如何学编程 point in the vi

I need to set a property of an NSView loaded from a Nib calculated using its initial bounds. Its bounds is still null inside - (void)awakeFromNib, so what is the first开发者_如何学编程 point in the view's lifecycle that I can access its bounds?


Set it in -viewDidMoveToWindow:


Indeed, Apple documentation clearly says:

Important: Because the order in which objects are instantiated from an archive is not guaranteed, your initialization methods should not send messages to other objects in the hierarchy. Messages to other objects can be sent safely from within awakeFromNib—by which time it’s assured that all the objects are unarchived and initialized (though not necessarily awakened, of course).

On iOS you would use the viewDidLoad method but it seems that is not necessarily avaible on Mac.

I believe you will find your answer in the stackoverflow post (this is a Mac developer solution specific not iOS but it seems it is what you are looking for).

0

精彩评论

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

关注公众号