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]
Related
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 have an UIViewController class(Say it is XXX). I present this view controller as modally by the code..
XXX *xxx = [ [XXX alloc] init];
[self presentModalViewController:xxx animated:YES];
[xxx release];
I want to add a navigation bar on the top of the XXX view. So I used UINavigationBar object in XXX's loadView method.
UINavigationBar *navBar = [ [UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:navBar];
[navBar release];
But, It throws an error as "EXC_BAD_ACCESS". Any help...?
Thanks
OPTION-1:
Try adding navigation bar from the XIB of viewController called XXX.
OPTION-2:
Add a UINavigationController and present it modally.
Replace your code :
XXX *xxx = [[XXX alloc] init];
[self presentModalViewController:xxx animated:YES];
[xxx release];
with this code:
XXX *xxx = [[XXX alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigation animated:YES];
[navigation release];
Hope this helps you.
Replace your code with:
XXX *xxx = [[ [XXX alloc] init]autorelease];
[self presentModalViewController:xxx animated:YES];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigation animated:YES];
[navigation release];
I think it will solve your "EXC_BAD_ACCESS" problem.
you can try this by adding toolbar at the top of the view. In many cases i have seen for poping MODAL controller this is nice solution. but if you want to navigate more controllers from MODAL controller then you should use UINavigationController.
you do it like this:
XXX *xxx = [[XXX alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigationController animated:YES];
[xxx release];
[navigationController release];
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 problem, I have made this:
Impostazioni *impostazioni=[[Impostazioni alloc] initWithNibName:#"Impostazioni" bundle:nil];
[self.navigationController presentModalViewController:aiuto animated:YES];
But I want to preserve the navigation bar in this modality:
[self.navigationController pushViewController:aiuto animated:YES];
[self.navigationController.navigationBar.backItem setTitle:#"iCalory"];
And I want use presentModalView how can I this? thanks
To add navigation controller in your code,
Impostazioni *impostazioni=[[Impostazioni alloc] initWithNibName:#"Impostazioni" bundle:nil];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController: impostazioni] autorelease];
[self.navigationController presentModalViewController:navigationController animated:YES];
Just add your view controller to a new navigation controller and present the navigation controller modally:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController: aiuto] autorelease];
[self presentModalViewController navigationController];
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];