views:

78

answers:

3

I have discovered that when my program starts, in one of my viewcontrollers the order of calling is viewDidAppear, viewWillAppear, viewDidAppear.

I was not expecting the first viewDidAppear to be called. What could be causing this and how do I fix it? ATM I have a flag in viewDiDAppear to check if viewWillAppear was called, but it's a hack.

The stacktrace (which is identical in bot calls to viewDidAppear)is:

#0  0x0000509e in -[MainView viewDidAppear:] at MainView.m:497
#1  0x3097e96e in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#2  0x30af3abe in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#3  0x30af4930 in -[UINavigationTransitionView _navigationTransitionDidStop]
#4  0x3091af0d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#5  0x3091ba9e in +[UIViewAnimationState popAnimationState]
#6  0x30af46fd in -[UINavigationTransitionView transition:fromView:toView:]
#7  0x30af3b01 in -[UINavigationTransitionView transition:toView:]
#8  0x30979f09 in -[UINavigationController _startDeferredTransitionIfNeeded]
#9  0x30a97d9c in -[UILayoutContainerView layoutSubviews]
#10 0x0040bd94 in -[CALayer layoutSublayers]
#11 0x0040bb55 in CALayerLayoutIfNeeded
#12 0x0040b3ae in CA::Context::commit_transaction
#13 0x0040b022 in CA::Transaction::commit
#14 0x308f942a in -[UIApplication _reportAppLaunchFinished]
#15 0x308fef33 in -[UIApplication handleEvent:withNewEvent:]
#16 0x308fad82 in -[UIApplication sendEvent:]
#17 0x309013e1 in _UIApplicationHandleEvent
#18 0x32046375 in PurpleEventCallback
#19 0x30245560 in CFRunLoopRunSpecific
#20 0x30244628 in CFRunLoopRunInMode
#21 0x308f930d in -[UIApplication _run]
#22 0x309021ee in UIApplicationMain
#23 0x00001e82 in main at main.m:14
A: 

Put a break point in viewDidAppear, then inspect the call stack in the debugger. It will tell you what is calling the method.

coneybeare
I've done that, but they are both coming from main, specifically UIApplicationMain(...)
John Smith
Why dont you add the stack traces here.
coneybeare
A: 

It's very likely that you want the behavior of viewDidLoad rather than viewDidAppear - viewDidAppear can be called multiple times by your ViewController when you're not expecting it to.

MHarrison
No. I want the viewDidAppear. You are not answering the question I asked. Again:Why is viewDidAppear being called without a corresponding viewWillAppear?
John Smith
A: 

When viewDidAppear is called, can you cancel another viewDidAppear in the event queue by following method ? Sometimes I use this to avoid some methods being called twice or more.

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(viewDidAppear) object:nil];
Toro