Call code before view loads objective C
How can I execute cod开发者_StackOverflow中文版e before the viewDidLoad method please?
Thanks
If you execute code in -(id)init, you have to pay attention when you use some codes like self.view.frame = .... or [self.view addSubView:xxx] inside -(id)init, it will load view and run -(void)viewDidLoad method before -(id)init return.
If you made your view with IB, then a method named -(void)awakeFromNib; would be called when your codes load view from IB. If you made view by codes, you can put those codes inside -(void)loadView to construct the view hierarchy.
The correct place depends on what exactly you want to do. You could put it in the correct -init...
method or the class initializer +initialize
. Or maybe you want to do this before you load your view.
精彩评论