简体   繁体   English

将带有导航 controller 的 tableView 添加到基于视图的项目中 - iPhone 编程

[英]Adding tableView with navigation controller to a view-based project - iPhone Programming

I have a view based project with a set of buttons.我有一个带有一组按钮的基于视图的项目。

When one of the buttons is pressed I would like a table view with a Navigation controller to be created.当按下其中一个按钮时,我想创建一个带有导航 controller 的表格视图。 I have this code in another project.我在另一个项目中有这段代码。

My code is basically this tutorial with some minor changes (just the first 2 parts): CODE我的代码基本上是本教程,有一些小的改动(只是前 2 部分): CODE

Is there a way to import this code into my main project so that when the button is pressed the preceding code executes?有没有办法将此代码导入我的主项目,以便在按下按钮时执行前面的代码?

EDIT:编辑:

I use this method to allow me to change views:我使用此方法允许我更改视图:

- (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 is the correct controller. RootViewController 是正确的 controller。 If I remove the 2 lines:如果我删除 2 行:

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

And replace vc with currentView in the rootview initialiser then the code works, and my table is displayed using my custom cells and successfully parses the xml and displays the correct data, but without a navigation controller.并在 rootview 初始化程序中用 currentView 替换 vc,然后代码工作,我的表使用我的自定义单元格显示并成功解析 xml 并显示正确的数据,但没有导航 controller。 However when I add the 2 lines above the table view doesnt work and I get an XML error code 5...Any ideas?但是,当我在表格视图上方添加 2 行时不起作用,我收到 XML 错误代码 5...有什么想法吗?

Thanks,谢谢,

Jack杰克

You can create a controller (which has your table view) and then create a navigation controller with its root controller as the controller having the table view. You can create a controller (which has your table view) and then create a navigation controller with its root controller as the controller having the table view. And from here you can present this navigation controller.从这里您可以展示此导航 controller。

Navigation controller has a method called as导航 controller 有一个方法称为

- (id)initWithRootViewController:(UIViewController *)rootViewController

UPDATE:更新:

// Create your root controller. // 创建你的根 controller。

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

// Create your navigation controller with its root controller. // 创建您的导航 controller 及其根 controller。

UInavigationController *navController = [UINavigationController initWithRootViewController:controller];

// Present your navigation controller. // 展示您的导航 controller。

[self presentModalViewController: navController animated:YES];

// Release root controller and nav controller... // 释放根 controller 和导航 controller...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TableView到基于视图的应用程序项目上的导航控制器? - TableView To Navigation Controller on the View-Based Application Project? iPhone-转换基于视图的项目 - iphone - transforming a view-based project iPhone:创建新的“基于视图的应用程序” =没有视图控制器? - iPhone: create new “View-based Application” = no view controller? iPhone基于视图的应用 - iphone view-based app 基于基于iPhone View的应用程序项目创建导航控制器 - Create Navigation Controller based on iPhone View Based Application Project iPhone“基于视图的应用程序”模板:如何加载视图控制器xib? - iPhone “View-based application” template: how is the view controller xib loaded? 如何将用C编写的现有项目与基于iphone视图的应用程序项目集成? - how can I integrate the existing project written in C with the iphone view-based application project? 将基于Xcode的基于视图的应用程序转换为基于导航的应用程序? - Convert Xcode view-based app to navigation-based app? 是否可以将基于视图的应用程序转换为基于导航的应用程序? - Is it possible to turn a View-Based App into a navigation-Based App? 我是否可以在基于iPhone View的应用程序中正确使用NSTimer? - Am I using NSTimer correctly in iPhone View-based app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM