Reputation: 1340
I am trying to push a UIViewController
(Called A) from viewWillAppear
OR viewDidAppear
of ViewController
(Called B). Which is working fine.
But when I am popping A... B doesn't push it(A) again (Or I can say It is not showing its view) ... But when I am trying same after disable AutoLayout for my Storyboard
, It is pushing A again after popping.
I have 3 solutions to resolve this issue... But I don't know why this is happening. Any one please update me about this issue. Thanks in advance.
When Auto Layout is enabled:
(ViewDidAppear)
rootViewController —————————————————————> demoViewController
(Push: animation:NO)
(Button Press)
demoViewController —————————————————————> rootViewController
(Pop: animation:NO)
As per code, rootViewController will push again demoViewController, But it is not showing demoViewController and navigationController is having demoViewController in its stack.
When Auto Layout is disabled:
Everything is working as we are assuming.
Upvotes: 1
Views: 1422
Reputation: 4695
See the answer given in this question: Pushing view controller within viewDidAppear doesn't work
In my situation what you are describing was happening with auto layout disabled. This helped
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 250 * USEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"myScreen"] animated:YES];
});
Upvotes: 2
Reputation: 27
You musn't push a view Controller
into another in viewDidAppear
or viewWillAppear
. Because after you have to set variables when you want to come back...
Have you set constraints in your storyboard
? Because it can become from it.
Upvotes: 0
Reputation: 1339
I don't know what view (and of what size) you have defined in the IB or in your code. Developers must have the through knowledge about using the AutoLayout feature in IB otherwise it leads to very nasty (unanticipated) bugs in the code.
So, i strongly recommend to go through this AutoLayout Guide: here I guess the contraints in views of viewcontroller A is giving the bug.
More precisely go to this page: Working with Constraints in Interface Builder
So, without trying couldbe or shouldbe be clear from this link.
Upvotes: 0