简体   繁体   English

UITabBarItem未使用的表达式结果

[英]Expression result unused for UITabBarItem

Im getting the warning "Expression result unused". 我收到警告“表达式结果未使用”。

在此处输入图片说明

I dont know why this is showing. 我不知道为什么这样显示。 It is working correctly. 它工作正常。 Showing the right title and the images so why the warnings? 显示正确的标题和图像,为什么要显示警告? what can i do to fix these warnings? 我该如何解决这些警告?

Thank you all for the help! 谢谢大家的帮助!

----------------------------------------------------- Edit 1 -------------------------------------------------- -编辑1

WHen i write it like this i get no warning. 当我这样写时,我没有收到警告。

   tabBarItem1 = [tabBarItem1 initWithTitle:@"Matcher Idag" image:[UIImage imageNamed:@"games-2.png"] selectedImage:[UIImage imageNamed:@"games-2.png"]];

BUT when i go to Product -> Analyze then it says: " Value stored to tabBarItem1 is never used 但是,当我转到“产品”->“分析”时,它说:“从未使用存储到tabBarItem1的值

That code is very, very wrong. 该代码是非常非常错误的。

Init methods return an object. 初始化方法返回一个对象。 You're supposed to use it, because sometimes the init method returns a different object than the one you started with. 您应该使用它,因为有时init方法返回的对象与开始时返回的对象不同。

You almost always use alloc and init together in a pair, eg: 您几乎总是成对使用alloc和init,例如:

tabBarItem1 = [[tabBarItem alloc] initWithTitle: @"title" 
  image: myImage
  selectedImage: anotherImage];

If you're not an experienced Objective-C developer and you're calling alloc and init separately, you are making a mistake. 如果您不是经验丰富的Objective-C开发人员,并且分别调用alloc和init,那么您会犯错。 I can count on the fingers of 1 hand the number of times I've used init where it wasn't in the alloc/init pattern I showed above 我可以用一只手的手指指望我使用init的次数(它不在上面显示的alloc / init模式中)

The code you posted doesn't make a lot of sense. 您发布的代码没有多大意义。 You shouldn't be sending init messages to objects that are already part of your tab bar. 您不应该向已属于选项卡栏的对象发送初始化消息。 That's a no-no. 那是不可以的。 Those objects have already been initialized, and you are only supposed to send one init message to an object in it's lifetime. 这些对象已经被初始化,您只能在其生命周期内向该对象发送一条初始化消息。 What you are doing is going to cause problems. 您正在做的事情会引起问题。 Big problems. 大问题。

Instead you should use the title and image properties: 相反,您应该使用title和image属性:

tableBarItem1.title = @"new title";
tableBarItem1.image  = myImage;
tableBarItem1.selectedImage  = mySelectedImage;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM