我創建了一個基於窗口的新應用程序,以及一個用於sublcasses UIViewController的RootViewController。我在AppDelegate中創建了一個UINavigationController,當我將UINavigationController的視圖添加到窗口中時,我確實在頂部看到了導航欄。但是,我似乎無法在導航欄中添加按鈕 - 沒有編譯錯誤,但按鈕(和標題)不顯示。代碼如下:BarButtonItem不顯示
- (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;
}
我在做什麼錯?
你嘗試設置在UIViewController子類的標題和rightBarButton呢?在我看來,'-viewDidLoad'似乎是一個合適的地方。還要確保UINavigationController不在你的UIViewController子類的'-viewDidLoad'裏面。 –