这几天我一直在纠结这个问题,我承认我需要帮助.
I've been stuck trying to puzzle this out for a couple days now, and I'll admit I need help.
我的应用程序的根视图控制器是一个标签栏控制器.我想让每个标签栏都有一个不同的导航控制器.这些导航控制器具有完全不同的行为.
The root view controller of my application is a tab bar controller. I want to have each tab bar a different navigation controller. These navigation controllers have completely different behavior.
那么我该如何根据类进行设置呢?根据 Apple 的文档,我不应该继承 UINavigationViewController
.那么我应该把驱动这些导航控制器的代码放在哪里呢?这一切都会被扔进 App Delegate 吗?那会造成不可能的混乱.
So how do I set this up in terms of classes? Per Apple's documentation, I'm not supposed to subclass UINavigationViewController
. So where do I put the code that drives each of these navigation controllers? Does it all get thrown in App Delegate? That would create an impossible mess.
此应用应在 iOS 4.0 或更高版本上运行.(实际上,我可能需要 iOS 4.2.)
This app should run on iOS 4.0 or later. (Realistically, I can probably require iOS 4.2.)
这取自我的一个应用程序.正如您所说,您不应该继承 UINavigationController
,而是按原样使用它们,并在 UINavigationController 的
上添加 viewcontroller.然后在每个 UINavigationController
中设置根 viewcontroller 之后,将 UINavigationController
添加到 UITabBarController
(哇!).
This is taken from one of my applications. As you say, you are not supposed to subclass UINavigationController
, instead you use them as they are and you add viewcontroller on the UINavigationController's
. Then after setting the root viewcontroller in each UINavigationController
, you add the UINavigationController
to the UITabBarController
(phew!).
所以每个选项卡都会指向"一个 UINavigationController
,它有一个常规视图控制器作为根视图控制器,并且它是根视图控制器(您添加的那个),将在按下选项卡时显示顶部有一个(可选)导航栏.
So each tab will "point" to a UINavigationController
which has a regular viewcontroller as root viewcontroller, and it is the root viewcontroller (the one you add) that will be shown when a tab is pressed with a (optional) navigationbar at top.
UITabBarController *tvc = [[UITabBarController alloc] init];
self.tabBarController = tvc;
[tvc release];
// Instantiates three view-controllers which will be attached to the tabbar.
// Each view-controller is attached as rootviewcontroller in a navigationcontroller.
MainScreenViewController *vc1 = [[MainScreenViewController alloc] init];
PracticalMainViewController *vc2 = [[PracticalMainViewController alloc] init];
ExerciseViewController *vc3 = [[ExerciseViewController alloc] init];
UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *nvc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc1 release];
[vc2 release];
[vc3 release];
nvc1.navigationBar.barStyle = UIBarStyleBlack;
nvc2.navigationBar.barStyle = UIBarStyleBlack;
nvc3.navigationBar.barStyle = UIBarStyleBlack;
NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nvc3, nil];
[nvc1 release];
[nvc2 release];
[nvc3 release];
self.tabBarController.viewControllers = controllers;
[controllers release];
这就是我从一个视图控制器转到另一个视图控制器的方式(这是通过点击表格视图中的一个单元格来完成的,但是正如您所见,pushViewController 方法可以在任何您想要的地方使用).
This is how I go from one viewcontroller to another one (this is done by tapping a cell in a tableview but as you see the pushViewController method can be used wherever you want).
(取自应用程序的另一部分)
(this is taken from another part of the app)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.detailedAnswerViewController == nil) {
TestAnsweredViewController *vc = [[TestAnsweredViewController alloc] init];
self.detailedAnswerViewController = vc;
[vc release];
}
[self.navigationController pushViewController:self.detailedAnswerViewController animated:YES];
}
self.navigationcontroller
属性当然是在每个被推送到 UINavigationController 层次结构的视图控制器上设置的.
The self.navigationcontroller
property is of course set on each viewcontroller which are pushed on the UINavigationController hierachy.
这篇关于选项卡式导航视图的正确设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!