我正在做一個簡單的應用程序來顯示飲料的詳細信息,現在我試圖添加一個視圖,允許用戶輸入自己的飲料。我已經創建了一個視圖來顯示細節,現在我只是將視圖傳遞給另一個控制器來創建添加飲料視圖。問題是,當我嘗試添加「取消」和「保存」按鈕時,它不會出現,儘管代碼沒有任何錯誤。我附上代碼作爲參考。xcode添加按鈕導航欄
這是在按下添加按鈕時使新視圖生效的代碼。 (我做了一個附加按鈕的工作原理,並拉起導航欄)
- (IBAction)addButtonPressed:(id)sender {
AddDrinkViewController *addViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailSecond"];
UINavigationController *addNavController = [[UINavigationController alloc] initWithRootViewController:addViewController];
[self presentModalViewController:addNavController animated:YES];
NSLog(@"Add button pressed!");
這是從addviewcontroller實現文件的代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)];
}
- (IBAction)save:(id)sender {
NSLog(@"Save Pressed");
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)cancel:(id)sender{
NSLog(@"Cancel Pressed");
[self dismissModalViewControllerAnimated:YES];
}
我已導入頭球addview成根控制器,所以我不認爲這是問題,你們有沒有看到有什麼不對?
我認爲這可能是一個問題,因爲我有一個標籤欄控制器,或者我是如何製作導航欄的故事板。我正在嘗試與故事板學習,但是我正在使用的這本書尚未使用那些東西進行更新,仍在使用筆尖文件。 –
導航欄是否顯示? –