以编程方式设置时无法显示我的 uitabbar
因此,我一直在到处寻找有关如何以编程方式创建 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加
try adding
您实例化 UITabBarController 的新实例并将 ViewControllers 列表设置为另一个实例,只需将行: 替换
为行:
You instantiating a new instance of the UITabBarController and setting the ViewControllers list to another instance, just replace the line:
with the line: