按 UITabBar 图标并选择.... 错误代码
我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您发布的代码中,每次出现时都需要将
viewController.tabBarItem
替换为item
。您要调查的选项卡栏项目是传递给此方法的item
参数。该方法未传递viewController
参数,因此viewController
变量未定义。这就是 XCode 用红色下划线的原因。In the code you posted, you need to replace the
viewController.tabBarItem
with justitem
both of the times it appears. The tab bar item that you want to investigate is theitem
parameter passed to this method. The method is not passed aviewController
parameter, so theviewController
variable is undefined. That is why XCode underlines it in red.