【发布时间】:2014-07-20 15:05:03
【问题描述】:
我在隐藏 UITabBarController 时遇到了麻烦,我将其定义为整个应用程序的 rootViewController。
我试图在显示的第一个视图上隐藏 UITabBarController - 它是整个应用程序的根视图控制器。这个想法是第一个视图有UIImageView 实例,它们跳转到定义的UIViewControllers(也被定义为根UITabBarController 的视图控制器)。
有没有办法让第一个视图控制器没有根 UITabBarController,但为所有其他定义为 viewControllers 的视图保留它?
这是AppDelegate 中的代码,将视图控制器和 UITabBarController 定义为 rootViewController。
- (void)initViewControllers {
anIdeaVC = [[IdeaViewController alloc] initWithNibName:@"IdeaViewController" bundle:nil];
[anIdeaVC setTabBarItem:[[[UITabBarItem alloc] initWithTitle:@"Idea" image:[UIImage imageNamed:@"iconIdee.png"] tag:0] autorelease]];
aListTableVC = [[ListTableViewController alloc] initWithStyle:UITableViewStylePlain];
[aListTableVC setTitle:@"List"];
aListNC = [[ListNavigationController alloc] initWithRootViewController:aListTableVC];
[aListNC setTabBarItem:[[[UITabBarItem alloc] initWithTitle:@"List" image:[UIImage imageNamed:@"iconList.png"] tag:0] autorelease]];
anInnMapVC = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
anInnMapNC = [[InnMapNavigationController alloc] initWithRootViewController:anInnMapVC];
[anInnMapNC setTabBarItem:[[[UITabBarItem alloc] initWithTitle:@"InnMap" image:[UIImage imageNamed:@"iconInnMap.png"] tag:0] autorelease]];
aSearchTableVC = [[SearchTableViewController alloc] initWithNibName:@"SearchTableViewController" bundle:nil];
[aSearchTableVC setTitle:@"Search"];
aSearchNC = [[SearchNavigationController alloc] initWithRootViewController:aSearchTableVC];
[aSearchNC setTabBarItem:[[[UITabBarItem alloc] initWithTitle:@"Search" image:[UIImage imageNamed:@"iconSearch.png"] tag:0] autorelease]];
tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:anIdeaVC, aListNC, anInnMapNC, aSearchNC, nil] animated:NO];
[tabBarController setSelectedViewController:anIdeaVC];
[tabBarController setDelegate:self];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self initViewControllers];
[window setRootViewController:tabBarController];
[window makeKeyAndVisible];
return YES;
}
提前感谢您的帮助:-)。
【问题讨论】:
-
你能描述一下功能目标吗?
-
在定义的视图中隐藏
UITabBarController(即应用程序的rootViewController) - 但不将该定义的视图添加到UITabBarController本身。 -
我正在尝试获取您希望用户看到的内容。可能有一种方法可以在没有太多体操的情况下做到这一点。例如标签栏 vc 不必一直是根目录。
-
用户打开应用,看到一个视图没有
UITabBarController点击了这个视图中的一个图标(所有这些图标都指向一个定义为视图控制器的UIViewController在根视图控制器(= UITabBarController))。所有可以从第一个视图控制器访问的视图控制器的底部都有 UITabBarController。 -
好的 - 每次应用启动时都应该发生这种情况吗? (当它在后台时怎么样?)您真正要求的是 not 有时将标签栏 vc 作为根。这个带有图标的其他 vc 既可以呈现它(在其自身之上),也可以在用户选择后被它替换。我可以向您展示其中任何一个的代码,具体取决于更改发生的确切时间和频率。
标签: ios objective-c ios7