我想知道如何在新视图上显示标签控制器。
我的标签控制器上有3个项目:主页,信息,帮助
在家里,有一个按钮打开一个新视图,这个新视图称为“测试版”,但没有显示标签控制器,我不知道如何显示标签控制器,我不希望“测试版”作为标签项目虽然..任何帮助将不胜感激。
这是我到目前为止使用的一些代码
//this is in appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UIViewController *viewController2 = [[InformViewController alloc] initWithNibName:@"InformViewController" bundle:nil];
UIViewController *viewController3 = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
//this opens the new view called beta
@implementation HomeViewController
-(IBAction)Showbeta
{
betaViewController *betaViewController = [[betaViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:betaViewController animated:YES completion:NULL];
}
//this is in betaviewcontroller
@interface betaViewController ()
@end
@implementation betaViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
// self.window.rootViewController = self.tabBarController; --> this did not work
}
return self;
}
答案 0 :(得分:1)
如果我理解正确,您需要为该选项卡创建一个视图控制器,其导航控制器的根目录是home vc。然后,当您想要显示测试版视图时,您可以像任何其他导航控制器一样推动它,它就会停留在标签栏中。
所以你应该调整你的代码:
UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UIViewController *viewController2 = [[InformViewController alloc] initWithNibName:@"InformViewController" bundle:nil];
UIViewController *viewController3 = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:viewController1]
self.tabBarController = [[UITabBarController alloc] init];
//self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.tabBarController.viewControllers = @[navController, viewController2, viewController3];
答案 1 :(得分:0)
您可以在appDelegate类中声明tabController实例。 现在将您的主视图控制器指定为rootViewController。 单击主屏幕上的按钮,将出现一个应该有tabViewController的新视图。所以,你现在应该将rootViewController设置为: [[[UIApplication sharedApplication] delegate] window] .rootViewController = tabViewController;