我想在我的应用程序中创建一个 tabBar,但只能在详细 View 中创建,而不是在 AppDelegate 中创建。我正在搜索如何在谷歌中执行此操作,但我发现的所有内容都在 AppDelegate.m
我正在尝试做这样的事情。这向我显示了一个带有两个按钮(没有名称)的选项卡栏,但我想从一个带有 tabBar 的 FirstViewController 转到带有导航栏和一个 backItemButton 的两个项目 SecondViewController 或 ThirdViewController 之一,以便返回到 FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupTabBar];
}
- (void) setupTabBar {
tabBars = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
YPProfileViewController *profile = [[YPProfileViewController alloc] init];
YPProfileViewController *profile2 = [[YPProfileViewController alloc] init];
[localViewControllersArray addObject:profile];
[localViewControllersArray addObject:profile2];
tabBars.tabBarItem = profile2;
tabBars.viewControllers = localViewControllersArray;
tabBars.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);
[self.view addSubview:tabBars.view];
}
最佳答案
至少这对我有用。
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = @"FIRST";
vc1.view.backgroundColor = [UIColor blueColor];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = @"SECOND";
vc2.view.backgroundColor = [UIColor redColor];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = @[vc1,vc2];
tabBar.selectedIndex = 1;
tabBar.view.frame = CGRectMake(50, 50, 220, 320);
[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];
关于iphone - 仅以编程方式为不在 AppDelegate 中的一个 ViewController 创建 TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18724193/