开发者

How to add a navigation bar to a table view?

I want to display a settings table modally, but I'开发者_Go百科m having trouble getting navigation bar at the top (to show the title and a done button). I can add the bar as a subview to the tableview, but then it scrolls with the tableview and I want to it to stay put at the top.


The best approach to this problem is to declare a UINavigationController in the previous view and then you get the nav bar automatically without interrupting the tableview behavior in your current view.

Example from the AppDelegate:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewTestViewController alloc] initWithNibName:@"ViewTestViewController" bundle:nil]; 
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;


If you are showing it modally, you can do something like this. Here, I am trying to show EnterScreenController modally, and I add a navigation Bar on top like this.

EnterScreenController *enterScreenController = [[EnterScreenController alloc] initWithNibName:@"EnterScreenController" bundle:[NSBundle mainBundle]];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:enterScreenController];

navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:navController animated:YES];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜