按 UITabBar 图标并选择.... 错误代码

发布于 2024-12-09 16:27:14 字数 532 浏览 5 评论 0原文

我使用 UITabbar 因为我喜欢图标设计。但我不使用 UIButtons。我有两个图标按钮和一个标签。

我已经委托了这个方法。如果单击第一个图标和第二个图标,我的 NSLog 将不会出现。我的这段代码出现警告 Xcode。你如何解决这个问题?

    - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
     if ([viewController.tabBarItem.title isEqualToString:@"FIRST"])
      { 
          label.hidden = YES;
          NSLog(@"FIRST");
       } else if ([viewController.tabBarItem.title isEqualToString:@"SECOND"])
      {
          label.hidden = NO;
          NSLog(@"SECOND");
       }

  }

I am using UITabbar because I like the Icon design. But I don't use UIButtons. I have two icon buttons and one label.

I've delegate method this. My NSLog won't appear if click first icon and second icon. I have this code appear warnings Xcode. How do you fix this?

    - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
     if ([viewController.tabBarItem.title isEqualToString:@"FIRST"])
      { 
          label.hidden = YES;
          NSLog(@"FIRST");
       } else if ([viewController.tabBarItem.title isEqualToString:@"SECOND"])
      {
          label.hidden = NO;
          NSLog(@"SECOND");
       }

  }

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

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

发布评论

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

评论(1

三生池水覆流年 2024-12-16 16:27:14

在您发布的代码中,每次出现时都需要将 viewController.tabBarItem 替换为 item 。您要调查的选项卡栏项目是传递给此方法的 item 参数。该方法未传递 viewController 参数,因此 viewController 变量未定义。这就是 XCode 用红色下划线的原因。

In the code you posted, you need to replace the viewController.tabBarItem with just item both of the times it appears. The tab bar item that you want to investigate is the item parameter passed to this method. The method is not passed a viewController parameter, so the viewController variable is undefined. That is why XCode underlines it in red.

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