Oliver
Oliver

Reputation: 23550

Pop-up modal with UITableView on iPhone (follow)

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, ...)

Upvotes: 1

Views: 2397

Answers (1)

Stephen Darlington
Stephen Darlington

Reputation: 52565

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];

Upvotes: 2

Related Questions