我创建了一个新的基于窗口的应用程序,以及一个Subcomcasses UIViewController的RootViewController。我在AppDelegate中创建了一个UINavigationController,当我将UINavigationController的视图添加到窗口时,我看到顶部的导航栏。但是,我似乎无法在导航栏中添加一个按钮 - 没有编译错误,但按钮(和标题)没有显示。代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RootViewController * rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:nil action:nil];
navigationController.title = @"Foo";
navigationController.navigationItem.rightBarButtonItem = next;
[self.window addSubview:navigationController.view];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
我做错了什么?
答案 0 :(得分:0)
可能是样式:仅在编辑模式下使用的UIBarButtonItemStyleDone为YES。如果在Root控制器或子视图控制器中,您可以尝试调用self.editing = YES,但在AppDelegate中则不能。
答案 1 :(得分:0)
改变这个:
navigationController.navigationItem.rightBarButtonItem = next;
到此:
rootViewController.navigationItem.rightBarButtonItem = next;