如何以编程方式将导航栏添加到presentModalViewController?
问题描述:
如何以编程方式将导航栏添加到presentModalViewController? 我知道默认的导航栏将在pushViewController .. 希望你的帮助...如何以编程方式将导航栏添加到presentModalViewController?
答
使用viewDidLoad中的这段代码。
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
这会将导航栏添加到您的视图。
答
这可以帮助你
PopoverView *foo = [[PopoverView alloc] initWithNibName:@"PopoverView" bundle:nil];
// Here you pass through properties if you need too.
// ...
UINavigationController *navC = [[UINavigationController alloc] initWithRootView:foo];
[foo release];
[self.navigationController presentModalViewController:navC animated:YES];
那你是怎么添加一个导航栏,以模态。
答
尝试添加以下内容到浏览做负载
[self.navigationController setNavigationBarHidden:NO animated:YES];
+0
我不知道,这不适合我。我在viewDidLoad中尝试了这两种方法,并且当呈现视图控制器实例化呈现的控制器时 – SimplGy 2015-07-22 20:31:36
的可能重复的[添加导航栏,以编程的UITableViewController?](http://*.com/questions/2700990/adding-a-navigationbar-to -uitableviewcontroller-programmingmatically) – rmaddy 2013-02-13 04:18:17
UINavigationController * navController = [[[UINavigationController alloc] initWithRootViewController:tableViewController] autorelease]; [self presentModalViewController:navController animated:YES];试试这个 – 2013-02-13 04:20:43
您可以通过拖放操作直接从界面生成器中将导航栏添加到xib文件中。 – 2013-02-13 04:31:43