0

我有一个关于 UINavigationController 的问题。我所做的是,我设置了一个导航控制器来处理一个视图控制器,我们将其命名为 A。现在我要做的是在视图控制器 A 上放置一个 UIView,并在该视图之上放置一个 tableview。tableViewcontroller 及其委托在单独的类中定义。现在我想做的是在用户单击表格单元格时使用“pushViewController”方法推送一个新的视图控制器。我是否必须将导航控制器的引用一直传递到我的 tableview 控制器?或者我应该如何从 tabelviewcontroller 类中获取我的导航控制器?

4

2 回答 2

1

这是我能够开始工作的教程。

我还阅读了有关该主题的官方 SDK 文档: Combining Tab Bar and Navigation Controllers。由于我仍在学习,因此本教程对我的帮助超过了文档。

否则试试这段代码

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

// Create instance of UINavigationController
UINavigationController *myNavigationController;
// Create initialized instance of UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// Create initialized instance of NSMutableArray to hold our UINavigationControllers
NSMutableArray *tabs = [[NSMutableArray alloc] init];

// Create first UIViewController
UIViewController *myFirstViewController = [[UIViewController alloc] init];
[myFirstViewController setTitle:@"First"];
// Initialize the UINavigationController
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
// Add UINavigationController to you tabs
[tabs addObject:myNavigationController];
// Release UIViewController and UINavigationController
[myFirstViewController release], [myNavigationController release];

// Create second UIViewController
UIViewController *mySecondViewController = [[UIViewController alloc] init];
[mySecondViewController setTitle:@"Second"];
// Initialize the UINavigationController
myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController];
// Add UINavigationController to you tabs
[tabs addObject:myNavigationController];
// Release UIViewController and UINavigationController
[mySecondViewController release], [myNavigationController release];

// Add the tabs to the UITabBarController
[tabBarController setViewControllers:tabs];
// Add the view of the UITabBarController to the window
[self.window addSubview:tabBarController.view];
}
于 2012-09-27T14:34:18.533 回答
1

在您拥有 UITableViewDelegates 的单独 UITableView 类中说(yourTableView),id delegate; 从您的 viewController 中声明一个属性 A ,主题yourTableView.delegate = self;

也许在 yourTableViewClass 的 didSelectRowAtIndexPath 中推送 didSelect 一如既往地创建要推送的 newController 实例(例如 newController)最后..

[delegate.navigationController pushViewController:newController animated:YES];

这里'delegate'原来是viewController A,你已经分配了一个UINavigationController。希望这有效

于 2012-09-27T14:48:54.767 回答