tags:

views:

15

answers:

2

Hi,

How can I execute code before the viewDidLoad method please?

Thanks

A: 

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.

Sven
I want to get data from a webservice and parse, etc before I load my view so I can load the view using this data
Lily
+1  A: 

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.

Toro