我想为UITabBarController创建一个UIView
这是我的.h文件的代码:
@interface TE : UIViewController <UITabBarControllerDelegate>{
UITabBarController *tabBarController;
}
@property (nonatomic,retain) UITabBarController *tabBarController;
@end
viewDidLoad方法:
UIViewController *testVC = [[T1 alloc] init];
UIViewController *otherVC = [[T2 alloc] init];
NSMutableArray *topLevelControllers = [[NSMutableArray alloc] init];
[topLevelControllers addObject: testVC];
[topLevelControllers addObject: otherVC];
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
[tabBarController setViewControllers:topLevelControllers animated:NO];
tabBarController.selectedIndex = 0;
self.view = tabBarController.view;
这会创建标签栏控制器,但是当我点击标签栏项目时,我会收到一个错误:
Thread1:Program receive signal: SIGABRT
编辑:我通过下载并修改了http://www.iphonedevcentral.com/create-uitabbarcontroller/版本来解决了这个问题
最佳答案
你上面说的你不想在appDelegate中创建tabBarController.为什么不?你会在哪里创建它? tabBarController必须是根视图控制器,不能是任何其他视图控制器的子级.
Btw,确保你实现:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
NSUInteger tabIndex = [tabBarController.viewControllers indexOfObject:viewController];
if (viewController == [tabBarController.viewControllers objectAtIndex:tabIndex] ) {
return YES;
}
return NO;
}
相关文章
- ios - 如何以编程方式将编程方式添加到以编程方式创建的UIView?
- objective-c - 当“以编程方式”创建UINavigationController和UITabBarController时,如何解决它们的功能(如viewWillAppear?)
- ios - 如何以编程方式创建标签栏控制器后添加导航界面(Swift)
- ios - 以编程方式在appdelegate中创建tabBarController
- ios - 如何以编程方式从编程方式显示一个popop,也是以编程方式创建的(不使用界面构建器)
- iphone - 如何以编程方式隐藏UITabBarController?
- ios - 如何以编程方式在AppDelegate中添加UITabBarController和UINavigationController?
- ios - 以编程方式设置UITabBarItem标题?
转载注明原文:ios – 以编程方式创建uiTabBarController - 代码日志