I have a table view nav controller that once a cell is selected it loads to a details view and then another button that leads to a sub details view. Whenever i try add anything to the third level nav view it crashes, be it a label, image, anything, even just image.hidden=YES; crashes? any ideas why?
try this
ThirdController *thirdController = [[ThirdController alloc] initWithNibName:#"ThirdController" bundle:nil];
[self.navigationController pushViewController:thirdController animated:YES];
[thirdController release];
Related
I have a 1st VC (view controller) that should be modal, and it has a child modal VC that sometimes should be presented as soon as 1st VC will appear, but sometimes not.
So from a root VC I want to present 1st VC, and over the 1st VC present the child modal VC. But the user should only see the child VC modal transition (not the 1st VC).
AFAIK the 1st VC can only present a modal VC after viewDidAppear:, so I don't know how to make this possible, since when viewDidAppear: is called, the 1st VC is already visible to the user.
Don't want the user to see 2 modal transitions one after the other, but just the last modal transition, the child's one.
Any hint?
I figured out the simplest solution to this if you still haven't found a suitable one. You can use a UINavigationController to hold the 2 nested view controllers you are trying to display modally.
In the function that is meant to display the modal views you could do something like:
- (IBAction)showView3
{
ViewController2 *new2 = [[ViewController2 alloc] init];
ViewController3 *new3 = [[ViewController3 alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:new2];
nav.navigationBarHidden = YES;
[nav pushViewController:new3 animated:NO];
[self presentModalViewController:nav animated:YES];
}
Then function in ViewController3 to dismiss it would have:
[self.navigationController popViewControllerAnimated:YES];
And the one in ViewController2 would have:
[self dismissModalViewControllerAnimated:YES];
The only issue I can see with this is aesthetics, as by default the transition from view3 to view2 is a horizontal animation but the one from view2 back to view1 is vertical. You could of course change that as well to make them all horizontal, or all vertical, or however you want.
You could have 1 modal view controller with 2 views. Then just pick which view you want to display when the view controller loads.
You should be able to put presentModalViewController anywhere you want, including viewWillAppear.
[self presentModalViewController:myModalViewController animated:NO];
edit: for anyone reading this, see my other (correct) answer, because this one isn't.
I have a navigation view controller which navigates between some tableviews and I've just added an "edit" button inside the cells of one of the tables. What I'd like to happen is for the user to tap the edit button inside the cell and for the navigation controller to shunt across a new view where all of that cell's content is laid out for easy editing.
The cell, however, has no access to the navigation controller and cannot push a new view controller on to its stack. How can I do what I want?
Note that I am not using segues and storyboards as it's an old app and I want to continue supporting devices running iOS 4.
You should set the target of the button to the UIViewController that is already on the stack?
If you don't want to add this new view to the Navigation (Stack), Simply use the PresentModalViewController
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:#"EditViewController" bundle:nil];
[self.navigationController presentModalViewController:editViewController animated:YES];
[editViewController release];
}
I'm not sure if you want this, but you can try:
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:editViewController animated:YES];
[editViewController release];
}
I've read the post : Pop-up modal with UITableView on iPhone
and I don't understand the following part of the answer (as I can't comment the original post, I create this new question) :
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:optionViewController];
Why allocate a new controller as the window from where the new optionController is called may already have one ?
What if I just write :
OptionViewController* optionViewController = [[OptionViewController alloc] initWithNibName:#"OptionView" bundle:nil];
[self.navigationController presentModalViewController:optionViewController animated:YES];
It seems to work...
If I have a list, that goes to a detail View, from where I switch to a modify view, and then from where I call this option window, what would be the code to use to call this optionWindow ? This one ? Any other one ? I really have a problem dealing with UINavigationController between screens... (where should be defined the first one, what should be passed between screens, when may I create a new one, ...)
Modal views don't use the UINavigationController of their parent. This means that if you need a "stack" of new view controllers in your modal view then you'll need to add your own. On the other hand, if you don't need the functionality of a navigation controller in your modal view then there's no reason to add one.
Here are sone more details of how I did it in two of my apps:
My root view controller has a UINavigationController. I open a modal view using this code:
TwitterPostViewController* vc = [[TwitterPostViewController alloc] init];
[viewc presentModalViewController:vc animated:YES];
[vc release];
The modal view is then dismissed using this code:
[self dismissModalViewControllerAnimated:YES];
I have a navigation based app. The root view is a list of items. From this root view you can tap on a table cell to an item's detail view. Or you can go to a form view to create a new item via the 'Add' button in the nav bar.
My question is how I can jump from the form view to the detail view once the new object has been created?
I don't want to push the detail view on top of the form view, because I want the root table view to be what the user see's after pushing the 'back' nav button form the detail view.
I've tried the following. It pops to the root view fine, but doesn't push the detail view after that..
[context save:&error];
[self.navigationController popToRootViewControllerAnimated:NO];
// display detail view
GoalDetailViewController *detailViewController = [[GoalDetailViewController alloc] initWithNibName:#"GoalDetailViewController" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.goal = goal;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Any help and direction would be much appreciated :)
Cheers!
Generally you would implement the add button using a view controller displayed modally.
[self presentModalViewController:modalViewController animated:YES];
meaning it appears from the bottom of the screen (see adding a contact). Then when they press done in the top right you can push the detail view controller on the navigation controller without animating it, making the back button go back to the original list view.
This isn't something you see too often in apps, but it can be accomplished like this:
// Get the current view controller stack.
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
// Instantiate your new detail view controller
GoalDetailViewController *detailViewController = [[GoalDetailViewController alloc] initWithNibName:#"GoalDetailViewController" bundle:nil];
detailViewController.goal = goal;
// Remove the topmost view controller from the stack
[viewControllers removeLastObject];
// Replace it with the new detail view controller
[viewControllers addObject:detailViewController];
// Change the view controller stack
[self.navigationController setViewControllers:viewControllers animated:YES];
// Clean up
[detailViewController release];
Exactly what animation you get is described here.
I have 3 different xib's. I am able to go back and forth between view 1 and view 2 with the following code...
This Code brings up the second view...
-(IBAction)startButtonClicked:(id)sender{
self.gamePlayViewController = [[GamePlayViewController alloc] initWithNibName:#"GamePlayViewController" bundle:nil];
[self.navigationController pushViewController:gamePlayViewController animated:YES];
[GamePlayViewController release];
}
This Code is executed in the second view and brings me back to the first view...
-(IBAction)backButtonClicked{
[self.navigationController popViewControllerAnimated:YES];
}
Now when I try to execute this code (in the second view) to get to the third view...I get SIGABRT and the app crashes...why does it work for the first view bringing up the second view, but not for the second view bringing up the 3rd view?
-(IBAction)nextView{
self.thirdViewController = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:thirdViewController animated:YES];
[thirdViewController release];
}
There's probably some object or outlet in ThirdViewController.xib that you've forgotten to configure or misconfigured. Compare and contrast ThirdViewController.xib and GamePlayViewController.xib, paying close attention to how you've configured ThirdViewController.xib's class names and outlets. In particular:
Make sure your File's Owner is properly set to ThirdViewController.
Make sure the view outlet of the File's Owner is properly connected to its view.