开发者

NavigationController from Modal View?

开发者 https://www.devze.com 2023-02-22 12:00 出处:网络
I\'m using a Navigation Controller. My RootViewController pushes a number of views but it also presents a modal view. That modal view presents a tableVi开发者_如何学Pythonew. So what I\'m trying to do

I'm using a Navigation Controller. My RootViewController pushes a number of views but it also presents a modal view. That modal view presents a tableVi开发者_如何学Pythonew. So what I'm trying to do is figure out of I can push the Navigation Controller across the modal view, then use it from that modal view to push the view with the tableView? or barring that, is there a way to implement a second Navigation Controller from the modal view?

The real issue is that I want to present the view with the tableView using a right to left transition, which of course is not available with modal views.

I have this code that SORT OF provides the right to left transition used by the Navigation Controller:

NewViewController *newViewController = [[NewViewController alloc] init];
[self presentModalViewController:newViewController animated:NO];

CGSize theSize = CGSizeMake(320, 460);
newViewController.view.frame = CGRectMake(0 + theSize.width, 0 + 20, theSize.width, theSize.height);
[UIView beginAnimations:@"animationID" context:NULL];
[UIView setAnimationDuration:0.5];
newViewController.view.frame = CGRectMake(0, 0 + 20, 320, 460);
[UIView commitAnimations];
[newViewController release];

The problem is that the OldViewController (the one calling the NewViewController) disappears immediately so the NewViewController transitions across a blank screen, instead of covering the OldViewController.


Presenting a UIViewController modally creates a whole new navigation stack. You could do something like this:

//Create the view you want to present modally
UIViewController *modalView = [[UIViewController alloc] init];
//Create a new navigation stack and use it as the new RootViewController for it
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:modalView];
//Present the new navigation stack modally
[self presentModalViewController:nav animated:YES];
//Release
[modalView release];
[nav release];

This can be done because UINavigationController is a subclass of UIViewController. When the new view is loaded, you can use it however you wish (push another view on top of it, us UIView animations like Waqas suggeste, etc').

I hope I got your question correctly. Do tell if I didn't.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号