UITabBar中的UITabBarItems在我单击项目后显示,而不是在应用程序启动时 [英] UITabBarItems in UITabBar show after I click the item not when application launches

查看:83
本文介绍了UITabBar中的UITabBarItems在我单击项目后显示,而不是在应用程序启动时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的这个应用程序有问题。

This application I'm writing has a problem.

我正在设置 UITabBar 应用程序窗口并在视图文件中设置图标。
但是当我运行应用程序时,第一个图标显示出来(因为视图已加载我猜),其他图标在我点击之前不会显示。

I'm setting up the UITabBar in my application window and set the icons in the view files. But when i run the app, the first icons show up (because the view is loaded I guess) and the other icons do not show up until I click them.

我是否需要在其他方法中实现 self.tabBarItem 而不是 viewDidLoad

Do i need to implement self.tabBarItem in some other method not viewDidLoad?

提前感谢大家!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    tabBar = [[UITabBarController alloc] init];

    SubscriptionsController *subscriptionsController = [[SubscriptionsController alloc] init];
    FavoritesController  *favoritesController  = [[FavoritesController  alloc] init];
    CategoriesController *categoriesController  = [[CategoriesController alloc] init];
    TagsController   *tagsController    = [[TagsController   alloc] init];
    HelpScreenController *helpScreenController  = [[HelpScreenController alloc] init];

    tabBar.viewControllers = [NSArray arrayWithObjects:
        subscriptionsController, 
        favoritesController, 
        categoriesController, 
        tagsController, 
        helpScreenController, 
        nil
        ];

    [window addSubview:tabBar.view];

    // Override point for customization after application launch.
    [window makeKeyAndVisible];
    return YES;
}

//The View

- (void)viewDidLoad {
    [super viewDidLoad];
    tabIcon = [[UITabBarItem alloc] initWithTitle:@"Abonime" image:[UIImage imageNamed:@"subscr.png"] tag:0];
    self.tabBarItem = tabIcon;
    [tabIcon release];
}


推荐答案

我认为你应该设置视图控制器指定的初始化程序中的tabBarItem属性(根据您的代码判断,每个控制器必须 -init )。事实上,标签栏控制器非常智能,可以根据需要加载视图,也就是说,应该在 viewDidLoad 被发送之前设置tabBarItem属性。

I think you should set the tabBarItem property in a view controller's designated initializer (judging from your code, it must be -init for each of the controllers). In fact, the tab bar controller is smart enough to load the views on demand, that is, the tabBarItem property should be set before viewDidLoad gets sent.

此外,您似乎泄漏了所有视图控制器。要解决此问题,请执行以下操作:

Also, you seem to be leaking all the view controllers. To fix that, do the following:

SubscriptionsController *subscriptionsController = [[[SubscriptionsController alloc] init] autorelease];

这篇关于UITabBar中的UITabBarItems在我单击项目后显示,而不是在应用程序启动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆