Why is my popToRootViewControllerAnimated not getting called? - iphone

I have even tried implementing a delay right before the call to popToRootViewControllerAnimated however that does no good either. It just does not get called.
-(IBAction) btnSignOut{
[[self tabBarController]setSelectedIndex:0];
[[self navigationController]popToRootViewControllerAnimated:NO];//DOES NOT GET CALLED
Overview *overviewController = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
//Lets place OverView in navController
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:overviewController];
// [[self navigationController] popToViewController:ComposeViewController animated:YES];
//Now lets display it
[self.tabBarController presentModalViewController:navController animated:YES];
[navController release];
[overviewController release];
}

It seems like the [self navigationController] does not contain any view to pop

Related

iphone- Push a view after poping earlier view

I have one view pushed on navigation.
Now I do following on click of button.
[self.navigationController popViewControllerAnimated:YES];
FreeStuffViewController * freeStuffVC=[[FreeStuffViewController alloc]initWithNibName:#"FreeStuffViewController" bundle:nil];
[self.navigationController pushViewController:freeStuffVC animated:YES];
[freeStuffVC release];
It only pops a view, but dint push new FreeStuffVc.
Please help.
Try this:
FreeStuffViewController * freeStuffVC=[[FreeStuffViewController alloc] initWithNibName:#"FreeStuffViewController" bundle:nil];
[self.navigationController pushViewController:freeStuffVC animated:YES];
NSMutableArray *viewArray = [[self.navigationController viewControllers] mutableCopy];
[viewArray removeObjectAtIndex:viewArray.count - 2];
self.navigationController.viewControllers = viewArray;
this works fine. Check it
UINavigationController *local = [[UINavigationController alloc]init];
[local popViewControllerAnimated:NO];
newView *nr=[[newView alloc]init];
[self.navigationController pushViewController:nr animated:YES];

Popping to first view controller of the project

I have a UINavigationController. I load a presentmodalviewcontroller over it. And I push 2 more view controllers over the presentmodalviewcontroller. If I need to move to my first view controller, what should be done?
Edit: I am also loading some UIView over the UIViewController on top of my stack. I have successfully removed that.
I have tried
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
but still its not working
This is how I am adding each view controller
First viewcontroller
FirstViewController *firstViewController =
[[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UINavigationController *navcontrol =[[UINavigationController alloc]initWithRootViewController:firstViewController];
[self presentModalViewController:navcontrol animated:YES];
[navcontrol release];
Second viewcontroller
SecondViewController *secondViewController = [[SecondViewController alloc]init] ;
[self.navigationController pushViewController: secondViewController animated:YES];
[secondViewController release];
Third viewcontroller
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
[self.navigationController pushViewController: thirdViewController animated:YES];
[thirdViewController release];
Ok. I got it.
myAppDelegate *appDelegate = (myAppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate.navigationController dismissModalViewControllerAnimated:YES];

How can I push a new viewController into an existing view within another view controller?

Is it possible to push a new viewController into an existing view within another view controller?
Here is my setup to begin with:
You can see that I have a UITableView. When a cell is tapped, a new view controller is pushed using this code;
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];
Unfortunately this looks like this though and sits on top of the bar at the top saying "Will Roberts"
Why is this happening as it's clearly outside of the view I set it to be pushed from...
Instead of "presentViewController", use
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController pushViewController:viewcontroller animated:YES];
[viewcontroller release];
or use modal view controller
[self presentModalViewController:viewcontroller animated:YES]
//Presenting new view controller with navigation controller will help you.
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];
//Edited
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[self presentModalViewController:nav1 animated:YES];

Remove modalViewController from view?

I have a view which pulls in another view using this code:
secondView = [[SecondView alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondView];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
The cancel button on this 2nd view has this:
[self.navigationController.modalViewController dismissModalViewControllerAnimated:YES];
But it doesn't appear to do anything. The view is still there and I can still interact with it. How do i remove it?
try:
[self.navigationController dismissModalViewControllerAnimated:YES]

presentModalViewController:animated: crash after dismiss

I'm currently having an issue with UIViewController's presentModalViewController:animated:.
I use the following code to set up and show the modal view controller:
UINavigationController *navigationController = [[UINavigationController alloc] init];
AddSerialController *serialController = [[AddSerialController alloc] initWithNibName:#"AddSerial" bundle:nil];
[navigationController pushViewController:serialController animated:NO];
[self.parentViewController presentModalViewController:navigationController animated:YES];
[serialController release];
[navigationController release];
The Application (running in iPhone Simulator) crashes as soon as dismissModalViewControllerAnimated: is called. GDB says it crashes at objc_msgSend.
If I comment out the last line of code (release of the navigation controller) everything works but I'm leaking a UINavigationController (as expected).
What the hell is going on here?
When you create a UINavigationController, you should give it a root view controller:
AddSerialController *serialController = [[AddSerialController alloc] initWithNibName:#"AddSerial" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:serialController];
[serialController release];
[self.parentViewController presentModalViewController:navigationController animated:YES];
[navigationController release];