开发者

Set objectAtIndex to be the integer in an NSString?

开发者 https://www.devze.com 2023-04-09 18:05 出处:网络
I\'ve got this: if ([[currentPlayer rankicon] isEqualToString:@\"0\"]) { self.casteImage.image = [casteImages objectAtIndex:0];

I've got this:

     if ([[currentPlayer rankicon] isEqualToString:@"0"]) {
     self.casteImage.image = [casteImages objectAtIndex:0];
     }

Which works. However, I have some 16 images to assign, and since the NSString and the index i开发者_StackOverflow中文版d are the same, I'd like to find a more efficient way to do this. I've also tried:

     NSInteger i = [[currentPlayer rankicon] integerValue];
     self.casteImage.image = [casteImages objectAtIndex:[i]];

But that doesn't work. Could be a bug elsewhere in my code(or some syntax error in the above), of course, but was wondering if I'm anywhere near the right track.


Remove [] around iin the second line.

0

精彩评论

暂无评论...
验证码 换一张
取 消