我使用此常量将 rgb 转换为 UIColor
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
当我在我的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
像这样
cell.textLabel.textColor = UIColorFromRGB(colours[indexPath.row]);`
和颜色定义为:
colours = [[NSArray alloc]
initWithObjects: @[@0x808000,@0x008080,@0x9999FF,@0x008080,@0x993366,@0xFFFF99,@0xFF8080,@0x0066CC,@0x008080,@0xFF99CC,@0x3366FF,@0x99CC00,@0x969696,@0xFF9900,@0x993300] , nil ];
我得到一个错误二进制表达式的无效操作数('id'和int)
强烈建议不要使用用于自省(introspection) Objective-C 对象指针的警告位掩码
有什么帮助吗?
最佳答案
您的 colours
数组包含 NSNumber
对象,所以你必须转换这些
到 UIColorFromRGB()
所期望的纯整数:
cell.textLabel.textColor = UIColorFromRGB([colours[indexPath.row] intValue]);
(注意
NSArray
和其他集合类只能存储 Objective-C 对象,并且@0x808000
是 [NSNumber numberWithInt:0x808000]
的快捷方式.)
关于ios - NSArray 在 tableView 函数中给我奇怪的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22158336/