Reputation: 3567
I just tracked down a crash I was having in my iOS app and it is related to willAnimateRotationToInterfaceOrientation being called before viewWillAppear.
I have an app with two views. Basically, when view1 disappears, I release some arrays, assuming they will be re-initialized when it re-appears in viewWillAppear.
However, if I change orientation in view2 then switch back to view1, this causes willAnimateRotationToInterfaceOrientation to happen before view1 has calledviewWillAppear and re-initialized everything and this causes a crash.
Is there any way to delay willAnimateRotationToInterfaceOrientation until after the view has appeared and everything has been re-initialized?
If not, the only solutions I can see are either not using willAnimateRotationToInterfaceOrientation (which results in an ugly looking orientation change) or not releasing my data when I switch from view1 to view2 which results in more memory being used than necessary.
Does anybody have any thoughts on what I should do?
Upvotes: 0
Views: 845
Reputation: 1480
You can use lazy-loading style code avoid your problem, like:
NSArray* someData;
-(void)somefun1{
if (!someData) {
[self loadData];
}
//use your data
}
-(void)somefun2{
if (!someData) {
[self loadData];
}
//use your data
}
-(void)loadData{
//some loading code
}
use lazy-loading style code you never need mind event calling order.
Upvotes: 1