如何以编程方式删除在父类 NIB 文件中创建的选项卡栏项?

2023-10-03移动开发问题
1

本文介绍了如何以编程方式删除在父类 NIB 文件中创建的选项卡栏项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在我的 iPhone 应用程序中,我有一个带有 三个标签 的公共标签栏,在按下按钮后会从多个视图中呈现.我遵循的方法是 Tweetie 应用程序的工作流程,在 Robert Conn 帖子.

Within my iPhone application I have a common tab bar with three tabs that is presented from several views after pressing a button. The approach I followed was the workflow of Tweetie application, described in Robert Conn post.

注意主控制器是一个导航控制器;选项卡栏放置在导航堆栈的视图控制器的 NIB 文件中,选项卡之间的切换效果在委托的 didSelectItem 方法中处理.

Note that the main controller is a navigation controller; the tab bar is placed in a view controller's NIB file of the navigation stack, and the effect of switching between tabs is handled in a delegate didSelectItem method.

@interface GameTabBarController : UIViewController<UITabBarDelegate> {
  UITabBar *tabBar;
  UITabBarItem *lastGameTabBarItem;
  UITabBarItem *previousGamesTabBarItem;
  UITabBarItem *myBetsTabBarItem;

  NSArray *viewControllers;
  UIViewController *currentViewController;
}

@implementation GameTabBarController
  ...

  - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    UIViewController *viewController = nil;

    // Get the view controller linked to the tab bar item pressed
    ...

    // Switch to the view
    [self.currentViewController.view removeFromSuperview];
    [self.view addSubview:viewController.view];
    self.currentViewController = viewController;
  }

  ...
@end

由于标签栏的视图必须根据应用程序来自的视图控制器进行自定义,我已将此 GameTabBarController 设置为具有该标签栏的 NIB 文件的父类.然后,我创建了几个子类:

Since the views of the tab bar must be customized according to the view controller the application came from, I have made this GameTabBarController a parent class with that NIB file that have the tab bar. Then, I have created several children classes:

@interface FirstGameTabBarController : GameTabBarController {
  ...   
}

@interface SecondGameTabBarController : GameTabBarController {
  ...   
}

...

我的问题是,在某些子类中,我想删除与父类关联的 NIB 文件的第三个选项卡.但由于没有涉及 UITabBarController,我无法遵循您可以在网络上找到的典型方法,即删除标签栏项目的视图控制器.

My problem is that in some of the children classes I would like to remove the third tab of the NIB file associated with parent class. But since there is no UITabBarController involved, I cannot follow typical approaches you can found on the web, i.e. removing the view controller of the tab bar item.

我该怎么做?是否可以删除之前在 NIB 文件中添加的元素?

How can I do that? Is it possible to remove elements that has been previously added in a NIB file?

谢谢!!

更新解决方案非常简单......我只需替换标签栏项目,而不是视图控制器:

UPDATE The solution was so easy... I have just to replace the tab bar items, instead of the view controllers:

NSMutableArray *items = [NSMutableArray arrayWithArray:self.tabBar.items];
[items removeObjectAtIndex:2];
[self.tabBar setItems:items];

感谢@Praveen S 为我指明了正确的方向.

Thanks to @Praveen S for pointing me in the right direction.

推荐答案

以下代码有解决方案:

NSMutableArray *tbViewControllers = [NSMutableArray arrayWithArray:[self.tabBarController viewControllers]];
[tbViewControllers removeObjectAtIndex:2];
[self.tabBarController setViewControllers:tbViewControllers];

这篇关于如何以编程方式删除在父类 NIB 文件中创建的选项卡栏项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7