iphone - 将带有导航 Controller 的 tableView 添加到基于 View 的项目 - iPhone 编程

标签 iphone objective-c ios uitableview uinavigationcontroller

我有一个基于 View 的项目,带有一组按钮。

当按下其中一个按钮时,我希望创建一个带有导航 Controller 的表格 View 。我在另一个项目中有此代码。

我的代码基本上是本教程的一些小改动(只是前两部分): CODE

有没有办法将此代码导入到我的主项目中,以便在按下按钮时执行前面的代码?

编辑:

我使用此方法来允许我更改 View :

- (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 是正确的 Controller 。如果我删除这两行:

currentView = [[UINavigationController alloc] initWithRootViewController:vc];
        [self presentModalViewController: currentView animated:YES];

并在 Root View 初始化程序中将 vc 替换为 currentView,然后代码就可以工作,并且我的表格使用自定义单元格显示,并成功解析 xml 并显示正确的数据,但没有导航 Controller 。但是,当我在 TableView 上方添加 2 行时, TableView 不起作用,并且收到 XML 错误代码 5...有什么想法吗?

谢谢

jack

最佳答案

您可以创建一个 Controller (具有 TableView ),然后创建一个导航 Controller ,其根 Controller 作为具有 TableView 的 Controller 。从这里您可以展示这个导航 Controller 。

导航 Controller 有一个名为

的方法
- (id)initWithRootViewController:(UIViewController *)rootViewController

更新:

//创建根 Controller 。

RootController *controller = [[RootController alloc] initWithNibName:@"RootControllerNibName" bundle:nil];

//创建导航 Controller 及其根 Controller 。

UInavigationController *navController = [UINavigationController initWithRootViewController:controller];

//展示您的导航 Controller 。

[self presentModalViewController: navController animated:YES];

//释放根 Controller 和导航 Controller ...

关于iphone - 将带有导航 Controller 的 tableView 添加到基于 View 的项目 - iPhone 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6188430/

相关文章:

objective-c - 需要建议在 iOS 中处理大型矢量图形

ios - Swift 动态转换异常

iPhone多 View 流程问题

ios - PresentViewController(UIViewController) 不工作

iphone - 将多对多关系迁移到 Core Data 中的连接表

objective-c - 如何在 iOS 中监控后台位置?

iphone - 如何根据键盘自动移动 UIScrollView 以使 UITextfield 可见?

objective-c - 插件架构,访问应用程序中的代码?

objective-c - QTKitServer 保留在事件监视器中

ios - UIScrollView 改变边界