添加tableView与导航控制器到基于视图的项目 - iPhone编程
问题描述:
我有一个基于视图的项目与一组按钮。添加tableView与导航控制器到基于视图的项目 - iPhone编程
当其中一个按钮被按下时,我想创建一个导航控制器的表视图。我在另一个项目中有这个代码。
我的代码基本上是本教程有一些细微的变化(只是第2个部分): CODE
有没有一种方法,这样,当按下按钮导入此代码到我的主要项目前面的代码执行?
编辑:
我用这个方法来让我改变看法:
- (void) displayView:(int)intNewView{
NSLog(@"%i", intNewView);
[currentView.view removeFromSuperview];
[currentView release];
switch (intNewView) {
case 1:
currentView = [[View1 alloc] init];
break;
case 2:
currentView = [[View2 alloc] init];
break;
case 3:
currentView = [[View3 alloc] init];
break;
case 4:
currentView = [[View4 alloc] init];
break;
case 5:
vc = [[RootViewController alloc] init];
currentView = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController: currentView animated:YES];
break;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.view addSubview:currentView.view];
[UIView commitAnimations];
}
RootViewController的是正确的控制器。如果我删除了2行:
currentView = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController: currentView animated:YES];
而在rootview与currentView替代VC初始化器然后代码工作,并显示我的表,可以使用我的自定义细胞,并成功地解析XML并显示正确的数据,但不一个导航控制器。但是,当我添加表视图上方的2行不工作,我得到一个XML错误代码5 ...任何想法?
感谢,
杰克
答
您可以创建一个控制器(其中有你的表视图),然后创建它的根控制器具有表视图控制器导航控制器。从这里你可以展示这个导航控制器。
导航控制器有一个称为
- (id)initWithRootViewController:(UIViewController *)rootViewController
更新方法:
//创建根控制器。
RootController *controller = [[RootController alloc] initWithNibName:@"RootControllerNibName" bundle:nil];
//使用其根控制器创建您的导航控制器。
UInavigationController *navController = [UINavigationController initWithRootViewController:controller];
//呈现您的导航控制器。
[self presentModalViewController: navController animated:YES];
//发布根控制器和导航控制器...
嗨@pratikshabhisikar,我想我知道你来自哪里,但我仍然得到错误...我已经编辑我的帖子包括这个,你能帮忙吗?谢谢,杰克 – 2011-06-01 00:29:09
你可以通过跳过''[present presentModalViewController:currentView animated:YES]来尝试相同的代码;'' ? – 2011-06-01 05:46:44
是的,那有效,奇怪,我确定我昨天晚上累了,它没有......没有任何意识。无论如何感谢很多@pratikshabhisikar,问题解决了! – 2011-06-01 11:21:57