在没有 UITabBarController 的情况下从 UITabBar 中删除选项卡

发布于 2024-08-30 23:51:32 字数 346 浏览 5 评论 0原文

我使用的是没有控制器的 UITabBar。如果满足某些条件,我想从 UITabBar 中删除选项卡。例如,我的 UITabBar 在界面生成器中设置了 4 个选项卡。如果在编译时未启用分数模块,则应删除分数选项卡。

// defined in IB
#define kTabScores 1 
UITabBar *_tabBar;


// in viewDidLoad
#if !INCLUDE_SCORES_SUPPORT
    // this doesn't seem to work
    [[_tabBar viewWithTag:kTagScores] removeFromSuperview];
#endif

I'm using a UITabBar without a controller. I want to remove tabs from the UITabBar if certain conditions are met. For example, my UITabBar has 4 tabs set up in interface builder. If the scores module is not enabled at compile time, it should remove the scores tab.

// defined in IB
#define kTabScores 1 
UITabBar *_tabBar;


// in viewDidLoad
#if !INCLUDE_SCORES_SUPPORT
    // this doesn't seem to work
    [[_tabBar viewWithTag:kTagScores] removeFromSuperview];
#endif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-09-06 23:51:32

您是否尝试过使用 UITabBar?例如:

// defined in IB
#define kTabScores 1 
UITabBar *_tabBar;


// in viewDidLoad
#if !INCLUDE_SCORES_SUPPORT
    NSMutableArray *newItems = [NSMutableArray arrayWithArray:_tabBar.items];
    [newItems removeObjectAtIndex:0]; //your index here.
    [_tabBar setItems:newItems animated:YES];
#endif

Have you tried using the items property of the UITabBar? For instance:

// defined in IB
#define kTabScores 1 
UITabBar *_tabBar;


// in viewDidLoad
#if !INCLUDE_SCORES_SUPPORT
    NSMutableArray *newItems = [NSMutableArray arrayWithArray:_tabBar.items];
    [newItems removeObjectAtIndex:0]; //your index here.
    [_tabBar setItems:newItems animated:YES];
#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文