2011-05-19 80 views
11

你好我使用工具欄上的一個標籤欄按鈕,這個按鈕將顯示與表視圖下一個視圖,這裏是我的代碼PresentModalViewController沒有顯示在一個視圖導航欄

[self presentModalViewController:self.navigationController 
          animated:YES]; 

我的問題是,當我點擊這個標籤欄按鈕將顯示帶有tableview的下一個視圖,但不會顯示導航欄。因此,我無法在tableView中執行刪除操作。

如何解決這個問題?

回答

38

如果你沒有找到下一個類手段UINavigationBar,它沒有導航控制器,所以推前添加一個UINavigationController到下一個視圖。

嘗試這樣的:

NextViewController *nextViewController=[[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil]; 
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:nextViewController]; 
[self.navigationController presentModalViewController:navBar animated:YES]; 
[navBar release]; 
[nextViewController release]; 

看到這個stackoverflow question的編輯選項。

您可以簡單地添加一個按鈕,導航欄輕鬆

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(editTable)] autorelease]; 

-(void)editTable{ 
[tableView setEditing: YES animated: YES]; 
} 

所有最優秀的。

+0

self.navigationItem.rightBarButtonItem = self.editButtonItem; 這是顯示EditButton項目,現在如何調用Tableview的編輯方法 – iProgrammer 2011-05-19 11:00:13

+0

確定與編輯和完成button.And刪除記錄,但它正在刪除臨時工作正常。當重新開始我的應用程序,然後記錄仍然存在 – iProgrammer 2011-05-19 11:05:16

+0

- (空)的tableView:(UITableView的*)atableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 如果(editingStyle == UITableViewCellEditingStyleDelete){ [書籤removeObjectAtIndex: indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade]; [[NSUserDefaults standardUserDefaults] setObject:bookmarks forKey:@「Bookmarks」]; } } – iProgrammer 2011-05-19 11:06:22

0

,如果你使用的是像這樣

[self.navigationController pushViewController:nextController animated:YES]; 
+0

我知道這樣,但我不能使用presentModalviewcontroller? – iProgrammer 2011-05-19 09:54:20

+0

嘗試像這樣[[self navigationController] presentModalViewController:navigationController animated:YES];或是請繼續導航推 – 2011-05-19 10:05:46

+0

如果我使用presentModalViewcontroller然後如何顯示編輯按鈕爲Uitableview ..任何想法? – iProgrammer 2011-05-19 10:08:08

0

navigationcontroller使用添加導航欄作爲副視點與欄按鈕的新觀點。

試試這個

-(IBAction) editClick:(id)sender 
{ 
    [tableView setEditing:![tableView isEditing] animated:YES]; 
} 
+0

如何將該按鈕與tableView的編輯代碼連接起來? – iProgrammer 2011-05-19 10:15:20

3

該代碼被稱爲按鈕點擊事件ClassA的VC:

ClassBVC* bVc = [[ClassBVC alloc] initWithNibName:@"ClassBVC" bundle:nil]; 
    UINavigationController* tempNavCon = [[UINavigationController alloc] initWithRootViewController:bVc]; 
    [self presentModalViewController:tempNavCon animated:YES]; 
    [tempNavCon release]; 
    [bVc release]; 
    bVc = nil 

;

,並在課堂上BVC鑑於沒有加載您做出UIbarbutton項目如:

UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked:)]; 
    [barButton setTitle:@"Back"]; 
    [self.navigationItem setLeftBarButtonItem:barButton]; 
    [barButton release]; 

而且在buttonClickedMethod簡單地忽視了模型控制器:

-(void)backButtonClicked:(id)sender 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 
1

那是因爲你正在使用模態帶來新的視圖控制器。

模態添加/呈現視圖控制器將不會添加到導航控制器堆棧