我没有从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;
}
但是,标签栏显示为白色且为空。我在哪里犯了错误?感谢。
答案 0 :(得分:0)
确保tabBar正确启动,并在viewDidLoad方法中添加tabBar以查看[self.view addSubview:tabBarController.view];