UITabBarController以编程方式添加,但标签栏不显示

时间:2012-06-05 07:27:52

标签: ios xcode uitabbarcontroller uitabbar

我没有从UIWindow开始,而是从UIView开始添加UITabBarController

我在documentFileName中有一个文件名数组,希望在子视图中逐个加载它们,每个都在一个标签中。

viewControllers = [[NSMutableArray alloc] init];
(NSString *tempStr in documentFileName) {
Subview *subviewController = [[Subview alloc] initWithFileName:tempStr];
    [viewControllers addObject:subviewController];
}
tabBarController.viewControllers = viewControllers;
[self.view addSubview:tabBarController.view];
}

在SubView.m中:

- (id) initWithFileName:(NSString *)fileName {
    isiPhone = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
    if (self = [super initWithNibName:((isiPhone)?@"NFLSPromDressingsSubview_iPhone":@"NFLSPromDressingsSubview_iPad") bundle:nil])
    {
        currentFileName = fileName;
    }
    return self;
}

- (void) viewDidLoad {
    [self loadDocuments];
    UITabBarItem *theItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:[documentFileName indexOfObject:currentFileName]];
    self.tabBarItem = theItem;
}

但是,标签栏显示为白色且为空。我在哪里犯了错误?感谢。

1 个答案:

答案 0 :(得分:0)

确保tabBar正确启动,并在viewDidLoad方法中添加tabBar以查看[self.view addSubview:tabBarController.view];