Tree Nguyen
Tree Nguyen

Reputation: 1199

Delay between viewDidLoad and viewDidAppear

so I'm doing some basic things on XCode when I have this weird bug(?).

There is a little delay between these 2 methods which I can't understand why Delay time

Some code that I think it is related.

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"viewDidLoad");
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"changing detail");
    [foodNameText setText:[food objectForKey:kTNFoodName]];
    [restaurantNameText setText: [food objectForKey:kTNRestaurantName]];
}

It's not really a big problem but I think it's weird cause my program is very simple so there shouldn't be a timeout for iOS to calculate anything. Any ideas why this happens?

Upvotes: 0

Views: 2911

Answers (2)

foundry
foundry

Reputation: 31745

ViewController events run in this order...

- (void)viewDidLoad
all objects are instantiated, but geometry (frames etc) is not yet setup correctly.

-(void)viewWillAppear:(BOOL)animated
Geometry is now correct, view hierarchy is ready for display

Here transition animations are run as appropriate

-(void)viewDidAppear:(BOOL)animated
Animations complete. Hierarchy is displayed as per geometry.

So for example if you use make a custom transition animation object, your animation code will be run after viewWillAppear and before viewDidAppear.

I have just run some simple tests.

enter image description here

App launch to VC1

2015-01-28 17:47:42.659 TestViews[14335:2062491] viewDidLoad
2015-01-28 17:47:42.660 TestViews[14335:2062491] viewWillAppear
2015-01-28 17:47:42.706 TestViews[14335:2062491] viewDidAppear


   1ms didLoad    -> willAppear
  46ms willAppear -> didAppear

Animated "Show" segue from VC1 to VC2.

2015-01-28 17:48:52.347 TestViews[14335:2062491] viewDidLoad
2015-01-28 17:48:52.347 TestViews[14335:2062491] viewWillAppear
2015-01-28 17:48:52.851 TestViews[14335:2062491] viewDidAppear

< 1ms didLoad     -> willAppear
504ms willAppear  -> didAppear

PushViewController from VC1 to VC2 animated:NO

2015-01-28 17:50:31.713 TestViews[14335:2062491] viewDidLoad
2015-01-28 17:50:31.713 TestViews[14335:2062491] viewWillAppear
2015-01-28 17:50:31.714 TestViews[14335:2062491] viewDidAppear

< 1ms didLoad    -> willAppear
  1ms willAppear -> didAppear

Animation timing is under the control of the animator. In the case of the 'Show' segue I imagine this is set to 0.5s by design

Upvotes: 3

Grady Player
Grady Player

Reputation: 14549

sorry couldn't really format as a comment...

the time you aren't accounting for is being used by:

[super viewDidAppear:animated]; 

log before that...

as to what that is doing, it could be loading data for a view or something... you will have to mess around to see if you can learn what it is doing... set a breakpoint and step in

Upvotes: 2

Related Questions