动态更改 TabBar 时管理 TabBar 操作

发布于 2024-10-15 21:27:54 字数 409 浏览 1 评论 0原文

我想知道如何管理动态变化的选项卡。

例如。我的主屏幕上有 4 个选项卡。当我单击第二个选项卡时。我现在有 5 个不同的选项卡。我知道如何动态添加它们,但我在管理单击它们时发生的情况时遇到了麻烦。

例如,主屏幕是我的第一个选项卡。

if (viewController == [self.tabBarController.viewControllers objectAtIndex:0]){

这将处理我对第一个选项卡的操作,但是当我单击第二个选项卡时更改选项卡时,我不希望我的第一个选项卡成为我的第一组选项卡中的第一个主页。有没有办法通过身份而不是索引号来管理选项卡栏点击?另一个例子是我的注销功能在第一组中是选项卡4,在第二组中是选项卡5。我不希望第二组中的第四个选项卡注销,目前它确实会导致它读取索引。

I am wondering how I can Manage tabs as they are changing dynamically.

For Example. On my Home screen I have 4 tabs. When I click the 2nd tab. I will now have 5 different tabs. I know how to add them dynamically but I am having troubles managing what happens when they are clicked.

For example Home screen is my first tab.

if (viewController == [self.tabBarController.viewControllers objectAtIndex:0]){

That will handle my actions for the first tab but when I change my tabs when I click the second tab I don't want my first tab to be the the first home page from my first set of tabs. Is there a way to manage tabbar click by identity and not by index number? Another example is my logout function is tabbar 4 in the first set and tab 5 in the second set. I dont want the the 4th tab in the second set to logout and currently it does cause it reads the index.

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

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

发布评论

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

评论(1

待"谢繁草 2024-10-22 21:27:54

Mike,在我看来,你对 UITabBar 的要求太高了。然而,我遇到过客户想要动态标签栏的情况。在这种情况下,代表团是你最好的朋友。

UITabBarDelegate:

– tabBar:willBeginCustomizingItems:
– tabBar:didBeginCustomizingItems:
– tabBar:willEndCustomizingItems:changed:
– tabBar:didEndCustomizingItems:changed:
– tabBar:didSelectItem:  required method

UITabBarControllerDelgate

Managing Tab Bar Selections
– tabBarController:shouldSelectViewController:
– tabBarController:didSelectViewController:
Managing Tab Bar Customizations
– tabBarController:willBeginCustomizingViewControllers:
– tabBarController:willEndCustomizingViewControllers:changed:
– tabBarController:didEndCustomizingViewControllers:changed:

这将让您管理当选项卡栏上出现某些内容时将执行的操作。

此外,您实际上可以通过更改视图控制器上的选项卡栏项目来更改选项卡栏上的图标,而无需将其删除,

UIViewController * controller =     [myTabBarController.tabBar.items objectAtIndex:kObjectIndex];

UIImage *someImage = [UIImage imageNamed:@"some_icon_on.png"];

UITabBarItem *someTabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString (@"SomeTabBarTitle",@"") image:someImage tag:kObjectIndex];


controller.tabBarItem = someTabBarItem;

我希望这对您有帮助。祝你好运!

Mike, it seems to me that you are asking too much for an UITabBar. How ever, I've been in your situation where a client wants a dynamic tab bar. Delegation is you best friend in this case.

UITabBarDelegate:

– tabBar:willBeginCustomizingItems:
– tabBar:didBeginCustomizingItems:
– tabBar:willEndCustomizingItems:changed:
– tabBar:didEndCustomizingItems:changed:
– tabBar:didSelectItem:  required method

UITabBarControllerDelgate

Managing Tab Bar Selections
– tabBarController:shouldSelectViewController:
– tabBarController:didSelectViewController:
Managing Tab Bar Customizations
– tabBarController:willBeginCustomizingViewControllers:
– tabBarController:willEndCustomizingViewControllers:changed:
– tabBarController:didEndCustomizingViewControllers:changed:

this will let you manage the actions that will be done when something is up on the tab bar.

Also you can actually change the icon on a tab bar without removing it by changing the tab bar item on the view controller

UIViewController * controller =     [myTabBarController.tabBar.items objectAtIndex:kObjectIndex];

UIImage *someImage = [UIImage imageNamed:@"some_icon_on.png"];

UITabBarItem *someTabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString (@"SomeTabBarTitle",@"") image:someImage tag:kObjectIndex];


controller.tabBarItem = someTabBarItem;

I hope this helps you. Best of luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文