Objective c 添加/隐藏uitabaritem

Objective c 添加/隐藏uitabaritem,objective-c,xcode4,Objective C,Xcode4,我有一个UITabBarController,想添加一个选项卡,能够使它消失。我用XCode添加了两个选项卡。您可以按程序添加第三个选项卡吗? 我知道这样的命令: [self setViewControllers: [NSArray arrayWithObjects: x1, nil] animated: NO]; 您可以检索使用XCode添加第三个视图的数组吗? 谢谢 我无法加载带有代码的视图。我从故事板创建了一个视图控制器,当我尝试从代码加载它时,我得到一个黑屏,使用以下代码: Vi

我有一个UITabBarController,想添加一个选项卡,能够使它消失。我用XCode添加了两个选项卡。您可以按程序添加第三个选项卡吗? 我知道这样的命令:

  [self setViewControllers: [NSArray arrayWithObjects: x1, nil] animated: NO];
您可以检索使用XCode添加第三个视图的数组吗? 谢谢


我无法加载带有代码的视图。我从故事板创建了一个视图控制器,当我尝试从代码加载它时,我得到一个黑屏,使用以下代码:

ViewControllerA *x1 = [[ViewControllerA alloc] init];
[self setViewControllers:[NSArray arrayWithObjects: x1, nil] animated:NO];
是的,如果使用,可以添加一个数组,其中包含前两个视图控制器和新的第三个视图控制器

例如,您可能希望这样做:

// 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];
        }
    }
}
您可能还希望为新的视图控制器提供一个带有标题和图像的关联选项卡栏项。退房

我已经为您链接了苹果文档,希望能对您有所帮助

是的,如果使用,可以添加一个数组,其中包含前两个视图控制器和新的第三个视图控制器

例如,您可能希望这样做:

// 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];
        }
    }
}
您可能还希望为新的视图控制器提供一个带有标题和图像的关联选项卡栏项。退房


我已经为您链接了苹果文档,希望能对您有所帮助

在代理中创建自定义选项卡栏,以便创建一个与选项卡栏类似的视图,并在视图上设置1个图像视图和3个按钮(1个按钮设置为隐藏)在需要第三个按钮时在选项卡栏控制器中添加此视图启用第三个按钮时在代理中创建自定义选项卡栏,以便创建与选项卡栏类似的视图,并在视图中设置1个图像视图和3个按钮(1个按钮设置为隐藏)在需要第三个按钮时在选项卡栏控制器中添加此视图启用第三个按钮时

[请检查如何隐藏条形按钮][1][1]:[请检查如何隐藏条形按钮][1][1]: