我有一个UITabBarController,并希望添加一个选项卡,使它消失的能力。我用XCode添加了两个选项卡。您可以按程序添加第三个选项卡吗?我知道这样的命令:
[self setViewControllers: [NSArray arrayWithObjects: x1, nil] animated: NO];您可以检索使用XCode添加第三个视图的数组吗?谢谢
我无法用代码加载视图。我从情节提要中创建了一个视图控制器,当我尝试从代码加载它时,我得到一个黑色屏幕,使用以下代码:
ViewControllerA *x1 = [[ViewControllerA alloc] init];
[self setViewControllers:[NSArray arrayWithObjects: x1, nil] animated:NO];发布于 2012-06-04 19:07:42
是的,如果使用[UITabViewController setViewControllers: animated:],可以添加一个数组,其中包含前面的两个视图控制器和新的第三个视图控制器。
例如,您可能希望这样做:
// assuming you've set an IBOutlet to your tab bar controller
NSArray * currentSetOfViewControllers = [appTabBarController viewControllers];
if((currentSetOfViewControllers == NULL) || [currentSetOfViewControllers count] == 0))
{
NSLog( @"I don't see any view controllers; is my tab bar controller outlet set properly?")
} else {
NSMutableArray newSetOfViewControllers = [[NSMutableArray alloc] initWithArray: currentSetOfViewControllers];
if(newSetOfViewControllers)
{
ViewControllerA *x1 = [[ViewControllerA alloc] init];
if(x1)
{
[newSetOfViewControllers addObject: x1];
[appTabBarController setViewControllers: newSetOfViewControllers];
// release our alloc'd mutable array only if you do not have ARC turned on
[newSetOfViewControllers release];
}
}
}您可能还希望给新的视图控制器一个带有标题和图像的相关选项卡项。看看[UITabBarItem initWithTitle: image: tag:]。
我已经为你链接了苹果的文档,希望能对你有所帮助!
发布于 2012-06-05 10:37:18
在委托中创建自定义选项卡条,因此创建一个视图,就像选项卡栏一样,并在视图上设置1个图像视图和3个按钮(1个按钮集隐藏),然后在选项卡条控制器中添加此视图,当您需要第三个按钮启用第三个按钮时。
https://stackoverflow.com/questions/10883839
复制相似问题