以编程方式设置时无法显示我的 uitabbar

发布于 2024-11-25 09:49:51 字数 1833 浏览 1 评论 0原文

因此,我一直在到处寻找有关如何以编程方式创建 uitabbar 的示例。我尽力从每个示例中获取我需要的内容,并将我希望的应用程序的外观组合在一起:一个带有 2 个选项卡的选项卡栏的欢迎屏幕。

我有一个用于欢迎屏幕的视图控制器,其中有一个 UIButton 可以继续:

-(IBAction)aMethod:(id)sender {

    MyTabProjectViewController *controller = [[MyTabProjectViewController alloc] initWithNibName:nil bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
    }

Then in my MyTabProjectViewController.m I do this:


    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Setting up the view
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor whiteColor];
    self.view = contentView;    

    //Declaring all view controllers
    FirstView *first = [[FirstView alloc] init];
    SecondView *second = [[SecondView alloc] init];

    //Set titles for the view controllers
    first.title = @"First";
    second.title = @"Second";


    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);


    UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:first];
    UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:second];

    nvc1.navigationBar.barStyle = UIBarStyleBlack;
    nvc2.navigationBar.barStyle = UIBarStyleBlack;


    NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nil];

    self.tabBarController.viewControllers = controllers;

    [self.view addSubview:tabBarController.view];    
    }

由于某种原因,没有任何效果。当我单击按钮转到 MyTabProjectViewController 时,我看到一个空白页面。

So I have been looking all over the place for examples for how to create a uitabbar prpgrammatically. I tried my best to take what I need from every example and to put together how I want my app to look like: a welcome screen following a 2-tab tabbar.

I have a view controller for the welcome screen with a UIButton to move on:

-(IBAction)aMethod:(id)sender {

    MyTabProjectViewController *controller = [[MyTabProjectViewController alloc] initWithNibName:nil bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
    }

Then in my MyTabProjectViewController.m I do this:


    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Setting up the view
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor whiteColor];
    self.view = contentView;    

    //Declaring all view controllers
    FirstView *first = [[FirstView alloc] init];
    SecondView *second = [[SecondView alloc] init];

    //Set titles for the view controllers
    first.title = @"First";
    second.title = @"Second";


    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);


    UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:first];
    UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:second];

    nvc1.navigationBar.barStyle = UIBarStyleBlack;
    nvc2.navigationBar.barStyle = UIBarStyleBlack;


    NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nil];

    self.tabBarController.viewControllers = controllers;

    [self.view addSubview:tabBarController.view];    
    }

From some reason nothing works. When I click on the button to go to MyTabProjectViewController I see a blank page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-12-02 09:49:51

尝试添加

tabBarController.selectedIndex = 0;

try adding

tabBarController.selectedIndex = 0;
半衾梦 2024-12-02 09:49:51

您实例化 UITabBarController 的新实例并将 ViewControllers 列表设置为另一个实例,只需将行: 替换

self.tabBarController.viewControllers = controllers;

为行:

tabBarController.viewControllers = controllers;

You instantiating a new instance of the UITabBarController and setting the ViewControllers list to another instance, just replace the line:

self.tabBarController.viewControllers = controllers;

with the line:

tabBarController.viewControllers = controllers;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文