ios - NSArray 在 tableView 函数中给我奇怪的警告

标签 ios objective-c uicolor

我使用此常量将 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/

相关文章:

ios - 为什么只有第一个任务退出后才调用dispatchGroup.notify?

ios - 如何在两个 UIView 之间实现 "90% slide"

ios - 导航栏不显示

ios - 如何将我的设备 token (NSData) 转换为 NSString?

ios - 在 Xcode 6 中测试覆盖率文件

ios - Swift 字符串作为 UIColor 对象

android - 如何从 WebView 获取可视化/部分文本?

ios - 为设备构建时遇到错误 - flutter

ios - 用另一种颜色替换图像中的特定颜色

uibutton - 如何正确地从 RGB 值初始化 UIColor?