-1

我想知道如何在新视图上显示选项卡控制器。

我的标签控制器上有 3 个项目:主页、信息、帮助

在主页上,有一个按钮可以打开一个新视图,这个新视图称为“beta”,但不显示选项卡控制器,我不知道如何显示选项卡控制器,但我不希望“beta”作为选项卡项。 .

任何帮助将不胜感激。

这是我到目前为止使用的一些代码

//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;
}
4

2 回答 2

1

如果我理解正确,您需要将该选项卡的视图控制器设置为导航控制器,其根是主 vc。然后,当您想要显示 beta 视图时,您只需像任何其他导航控制器一样推送它,它就会停留在选项卡栏中。

因此,您应该将代码调整为以下内容:

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];
于 2013-07-13T15:01:26.117 回答
0

您可以在 appDelegate 类中声明 tabController 实例。现在将您的主视图控制器分配为 rootViewController。单击主屏幕上的按钮会出现一个新视图,该视图应该有一个 tabViewController。因此,您现在应该将 rootViewController 设置为: [[[UIApplication sharedApplication] delegate] window].rootViewController = tabViewController;

于 2013-07-13T15:23:09.730 回答