简体   繁体   中英

converting to boxing syntax requires casting UIBarMetrics Warning

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

How can I solve this warning?

在此处输入图片说明

To get rid of the warning use

[NSNumber numberWithInteger:metrics]

or

[NSNumber numberWithInt:(int)metrics]

because metrics is an NSInteger and numberWithInt accepts int not NSInteger.

But what you really want is

[self backgroundImages][(int)metrics];

You try to pass NSNumber as a index to your array but you should pass int instead:

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

I assume backgroundImages is array. BarMetrics is an UIBarMetrics type you cannot pass it as an int.

You can do something like that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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