2

我正在展示一個使用根控制器(這是一個UITableViewController)初始化的模式導航欄控制器。當我初始化UINavigationBarController以模態呈現它時,我還會添加一個「提交」按鈕作爲右欄按鈕項目。一切工作正常(加載根視圖和模態演示文稿)但是,右鍵不顯示。 張貼下面的代碼 -將BarButtonItem添加到模態導航視圖控制器

-(IBAction) presentAddLeaveRequestModally { 
    AddLeaveRequestViewController *leaveRequestViewController = [[AddLeaveRequestViewController alloc] init]; 
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:leaveRequestViewController]; 
    UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit" 
                    style:UIBarButtonItemStyleBordered 
                    target:self 
                    action:@selector(submitLeaveRequest)]; 
    navController.navigationItem.rightBarButtonItem = submitButton; 
    [self.homeTabBarController presentModalViewController:navController animated:YES]; 
} 

任何想法,如果我失去了一些東西明顯?

回答

7

得到了問題......正在向navController的navigationItem中添加rightBarButtonItem ...我應該將其添加到viewDidLoad中的rootViewController的navigationItem中。

UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit" 
                   style:UIBarButtonItemStyleBordered 
                   target:self 
                   action:@selector(submitLeaveRequest)]; 
self.navigationItem.rightBarButtonItem = submitButton; 
+1

爲什麼我們不能在推送或呈現destinationViewController之前添加? – iTag 2015-06-22 14:05:51

相關問題