转换为装箱语法需要转换UIBarMetrics警告

时间:2013-12-11 11:37:31

标签: ios objective-c uiimage uibarmetrics

[self backgroundImages][[NSNumber numberWithInt:barMetrics]] = backgroundImage;

如何解决此警告?

enter image description here

2 个答案:

答案 0 :(得分:2)

要摆脱警告使用

[NSNumber numberWithInteger:metrics]

[NSNumber numberWithInt:(int)metrics]

因为metrics是NSInteger而numberWithInt接受int而不是NSInteger。

但你真正想要的是

[self backgroundImages][(int)metrics];

答案 1 :(得分:1)

您尝试将NSNumber作为索引传递给您的数组,但您应该传递int:

[self backgroundImages][It should be an int number] 

我认为backgroundImages是数组。 BarMetrics是一种UIBarMetrics类型,您无法将其作为int传递。

你可以这样做:

int i = -1;
if (barMetrics == UIBarMetricsDefault)
    i = 0;
if (barMetrics == UIBarMetricsLandscapePhone)
    i = 1;
// and so on....
[self backgroundImages][i]