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];
Related
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];
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];
I want to call secondview from my current view but this code suggested by someone is not working properly
UINavigationController *nav=[[UINavigationController alloc] initWithNibName:#"Second" bundle:[NSBundle mainBundle]];
[nav pushViewController:#"Second" animated:YES];
Why are you pushing an NSString onto a UINavigationController? I think what you want is:
SecondView * vc = [[SecondView alloc] initWithNibNamed:#"SecondView"];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
Hope that Helps!
You can use the presentModalViewController for the second view.
hope this will help you.
[self.navigationController presentModalViewController:SecondView animated:YES];
I suggest you put naviagtionbar initialization in your application:didFinishLaunchingWithOptions: if it's your rootViewController. You can initiate it with rootViewController, like so:
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:firstViewController_1];
self.window.rootViewController = nav;
[nav release];
Push other views in your view controller(e.g. your FirstViewController.m):
SecondViewController * secondViewController_2 = [[[NSBundle mainBundle] loadNibNamed:#"SecondViewController" owner:self options:nil] lastObject];
// Or: SecondViewController * secondViewController_2 = [[SecondViewController alloc] init...] autorelease];
[self.navigationController pushViewController:secondViewController_2 animated:YES];
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
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]