2011-05-19 104 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

那是因为你正在使用模态带来新的视图控制器。

模态添加/呈现视图控制器将不会添加到导航控制器堆栈