Push a new ViewController and Pop the last one from NavigationStack - ios

Hey Guys i want to push a new controller onto the navigation stack and then remove the controller where i pushed from.
Here is my Code :
WishDetailViewController *detailView = [self.storyboard instantiateViewControllerWithIdentifier:#"WishDetailView"];
detailView.transferWishID = [NSNumber numberWithFloat:[[response objectForKey:#"id"]floatValue]];
[self.navigationController pushViewController:detailView animated:YES];
[self.navigationController popViewControllerAnimated:NO];
Everthing works fine, but i got this message here inside the console :
2013-02-05 10:32:42.029 BWMApp[1444:1a603] nested pop animation can result in corrupted navigation bar
2013-02-05 10:32:42.392 BWMApp[1444:1a603] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
So what i am doing wrong and how can i prevent my app from throwing this error message ?

You can use setViewController. This example removes all and insert others, but give you the basic idea :)
NSMutableArray *viewCons = [[[self navigationController]viewControllers] mutableCopy];
[viewCons removeAllObjects];
[viewCons addObject:portraitTemp];
[viewCons addObject:self];
[[self navigationController] setViewControllers:viewCons];

There is no need to pop the "old" viewcontroller. The navigationController create a backbutton automatically. if you pop the viewcontoller from the stack there is no viewcontroller to "jump" back. This is the cause of message inside the console. The navigationController can't work correctly.

WishDetailViewController *detailView = [self.storyboard instantiateViewControllerWithIdentifier:#"WishDetailView"];
detailView.transferWishID = [NSNumber numberWithFloat:[[response objectForKey:#"id"]floatValue]];
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:detailView animated:YES];

Related

Xcode Can't Call/Dismiss viewcontroller from PopUp

This is going to take some explaining... So I'll do it in order:
I have a navigation controller where the rootViewController is called TipsCollectionViewController.
I have a UserViewController that's loaded as a popup:
UserViewController * userView = [[UserViewController alloc] initWithNibName:#"UserView" bundle:[NSBundle mainBundle]];
[userView setUEmail:email];
[self presentPopupViewController:userView animationType:MJPopupViewAnimationSlideTopBottom];
I then have another popup that loads on top of THAT popup:
Place *p = [placeArray objectAtIndex:indexPath.row];
DetailPlaceViewController *pvc = [[DetailPlaceViewController alloc] init];
[pvc setPlace:p];
NSLog(#"%#", p.PName);
[self presentPopupViewController:pvc animationType:MJPopupViewAnimationSlideTopBottom];
Now there's a reason I've done this: the AppDelegate features a Navigation controller and previously I loaded the UserView like this:
[self.navigationController presentViewController:userView animated:YES completion:nil];
But this meant that the UserView would load on the iPhone but not on the iPad for some odd reason. But when I switched it to the popup view it worked fine.
So now I load both the UserView and the DetailPlaceView in a popup... but now it CLOSES on the iPad but not on the iPhone.
Here's the code for closing the detail view:
- (void) didTapBackButton:(id)sender {
NSLog(#"View Controller Number: %lu", (unsigned long)self.navigationController.viewControllers.count);
if(self.navigationController.viewControllers.count > 1) {
[self.navigationController popViewControllerAnimated:YES];
NSArray *stack = self.navigationController.viewControllers;
TipCollectionViewController *tipsVC = stack[stack.count-1];
[tipsVC.collectionView reloadData];
}
I know there's a better way to handle this whole thing... but what should I be doing differently?
UPDATE
If I switch it back to:
[self.navigationController pushViewController:userview animated:YES];
...for the UserView on the iPhone and:
[self.navigationController pushViewController:pvc animated:YES];
...for the view that loads after that, then the UserView will load... but the next viewcontroller (the DetailPlaceViewController) won't load. I think that's my main problem. I could probably dismiss the second view controller at that point if I could get it to load. Any ideas?
[self presentPopupViewController:pvc animationType:MJPopupViewAnimationSlideTopBottom];
if you are using this,presentPopupViewController is used to display like modal view which cant be dismissed without any custom cancellation action.
To use popOverViewController method, use pushViewController. Then that one you can dismiss by this technique.
Ultimately all I had to do was switch:
[self.navigationController pushViewController:pvc animated:YES];
to:
[self presentViewController:pvc animated:YES];
And it works. It opens and closes the view and everything works as it should.
I'm getting a warning on the DetailView once you click an item:
Presenting view controllers on detached view controllers is discouraged <UserViewController: 0x16e02020>
So I'll wait a couple of days to accept my answer. Otherwise, despite the warning, it seems to be working.

iOS Push Segue (programmatically) sometimes stuck but won't crash

When I called:
[self.navigationController pushViewController:SOME_VIEW_CONTROLLER animated:YES];
the app randomly stuck (it didn't crash, so no error log). Have tried debugging it with no result.
Note that:
I called this pushViewController from a UIViewController category.
Is there any problem with that?
I am not using storyboard
The problem persist randomly (it doesn't happen all the time)
When it stuck, viewDidAppear won't be called (viewWillAppear, viewWillLayoutSubviews, viewDidLayoutSubviews still
called)
the problem never occured when I use animated:NO
Some code snippets:
- (void)routeToBookingDetailsForCustomer:(BookingModel *)booking {
VTBookingDetailsForCustomerViewController *vc = [VTBookingDetailsForCustomerViewController new];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];
}
Just found another thread with similar case:
pushViewController stuck or viewdidappear fail
I think you have to pass Nib name as well like this
- (void)routeToBookingDetailsForCustomer:(BookingModel *)booking{
VTBookingDetailsForCustomerViewController *vc = [[VTBookingDetailsForCustomerViewController alloc]initWithNibName:#"VTBookingDetailsForCustomerViewController" bundle:nil];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];
}
Nib name means your XIB name whatever XIB name for your VTBookingDetailsForCustomerViewController, you have to pass this in initWithNibName:#"yourXIBname"
Have you tried this approach?
someViewController *someVC = [someViewController alloc] initWithNibName:#"someViewController " bundle:NULL];
someVC.someVariable = someValue;
[self.navigationController pushViewController:someVC animated:YES];
Edit : Just saw 'Dipen Chudasama' already answered!
Are you using custom transition animations by implementing UINavigationProtocolDelegate combined with UIViewControllerInteractiveTransitioning?
I struggled with this issue in my own application and it turned out that I was incorrectly starting an interactive transition which I never finished. In this case all debugging showed me that the controller was pushed but UI was not updated until my app changed states.
Please try pushViewController code in main queue.
dispatch_async (dispatch_get_main_queue(), ^{
VTBookingDetailsForCustomerViewController *vc = [VTBookingDetailsForCustomerViewController new];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];
});

navigationController pop incorrect transition

I am presenting new viewController through navigationController with:
PTAgencyClients *pushedController = [[PTAgencyClients alloc] initWithNibName:#"PTAgencyClients"
bundle:nil
agency:agency];
[[self navigationController] pushViewController:pushedController
animated:YES];
and from this PTAgencyClients I am trying to pop this viewController with:
[[self navigationController] popViewControllerAnimated:YES];
Somehow when I pop it, it haven't this slight from-left-to-right animation. I am experimented a little and I seen mighty transition and in other cases transition of previous viewController from atop of this PTAgencyClients. What can initiate this behaviour?
Update
It Happens on both device and simulator.

ios how simulate back button in a ViewController

i have more viewcontroller that start from rootviewcontroller.
So for example i start with controller A so pass to B and go to C the third.
Normally to come back we need to push back on left top.
Instead i want to know if is possible instead use back button by code come previus view controller that in this case is B.
to go on the next i use this
ViewController *sc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[[self navigationController] pushViewController:sc animated:YES];
Simples
[[self navigationController] popViewControllerAnimated:YES];
See UINavigationController popViewControllerAnimated:(BOOL)animated

UINavigationcontroller pushViewController not working to get next Viewcontroller

I red nearly all the help which is provided, and i'm still confused. I have simple project in Xcode4.2 with sotoryboard. There i have Navigationcontroller and two Viewcontroler (one, two). If i'm trying to get from one to two with pushViewController its break down. Where is my problem. If i have the Navigationcontroler in my storyboard i shouldn't have problem to access it and use it, is it right? I don't won modal window application i use something like story board where the user can move back and front without lose the controls data. How should i do it right.
thanks for any help I'm new to apple developing :)
The only code :
- (IBAction)Next:(id)sender{
two* myNext = [[two alloc] initWithNibName:#"two" bundle:nil];
NSLog(#"%#", [self navigationController]);
NSLog(#"%d", [[[self navigationController] viewControllers] count]);
[[self navigationController] pushViewController:myNext animated:YES];
// [[self navigationController] pushViewController:myNext animated:YES];
// [myNext release];
}
The solution is to change the initialize UIViewController because of using storyboard you can't use initWithNibName. You have to use instantiateViewControllerWithIdentifier which use identifier property of UIViewController. The identifier property can by set in the sotryboard.
ViewController* myNext = [self.storyboard instantiateViewControllerWithIdentifier:#"Next"];

Resources