无法解决错误" [__ NSCFBoolean length]:无法识别的选择器发送到实例"

时间:2016-09-30 14:17:30

标签: ios objective-c xcode

代码

NSDictionary *dict = [self.catArray objectAtIndex:indexPath.row];
NSURL *U1 =[NSURL URLWithString:[dict objectForKey:@"img"]];

[DownloadManager downloadImageWithURL:[NSURL URLWithString:[dict objectForKey:@"img"]] completionBlock:^(BOOL succeeded, UIImage *image) {
    if (succeeded) {

        [cell.iconImgView setImage:image];

    }
}];

获取错误

  

[__ NSCFBoolean length]:发送到实例的无法识别的选择器

2 个答案:

答案 0 :(得分:0)

你的问题在于这一行:

NSURL *U1 =[NSURL URLWithString:[dict objectForKey:@"img"]];

问题是由您假设:

引起的
[dict objectForKey:@"img"]

返回NSString,实际上它返回表示布尔值的NSNumber

您需要弄清楚字典中的数据不正确的原因,或者您需要使用正确的密钥来获取URL。

答案 1 :(得分:0)

  [ [dict objectForKey:@"img"] stringValue];                

使用上面提到的代码来获取字符串值

相关问题