[self backgroundImages][[NSNumber numberWithInt:barMetrics]] = backgroundImage;
我该如何解决这个警告?
[self backgroundImages][[NSNumber numberWithInt:barMetrics]] = backgroundImage;
我该如何解决这个警告?
摆脱警告使用
[NSNumber numberWithInteger:metrics]
或者
[NSNumber numberWithInt:(int)metrics]
因为 metrics 是一个 NSInteger 并且 numberWithInt 接受 int 而不是 NSInteger。
但你真正想要的是
[self backgroundImages][(int)metrics];
您尝试将 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]