UINavigationItem是不是在我的ViewController
我正在寫在使用Xcode中的iOS簡單的應用中展示的,我試圖加載另一個ViewController
爲模式。起源HomeScreenViewController
(從UIViewController
繼承),我正在加載模態是源於項目的Storyboard。
然後,如一個按鈕按下事件的響應,我加載這個模式是這樣的:
-(IBAction)onAddButtonPressed:(UIButton *)sender {
MyAnotherViewController *vc = [[MyAnotherViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
}
類MyAnotherViewController
未在Storyborad因爲它的一個簡單類表示以顯示導航欄和文本域。該代碼是(部分代碼,其餘爲Xcode的自動生成方法):
@implementation MyAnotherViewController
- (void)viewDidLoad {
[self.navigationItem setTitle:@"Example"];
[self.view addSubview:[[UITextView alloc]initWithFrame:self.view.bounds]];
}
@end
該問題(也可以附圖所示),該navigationItem
未示出由於某種原因。
我也驗證了self.navigationItem
不是nil
而不是。更甚者,我可以在調試模式下看到標題實際設置爲「示例」。
你的幫助是十分讚賞,
乾杯......
嗨,你需要通過對其進行管理添加工具欄和欄按鈕項目。 – Hindu
感謝您的注意:)下面的Vinzzz給了我確切的答案! –