cell.theTitle.font=[UIFont fontWithName:@"Helvetical Bold" size:14];
cell.theTitle.text =[NSString stringWithFormat:@"%@",theCellData.contentTitle];
cell.theDescriptionLabel.text=theCellData.contentTitle;
cell.theDateAdded.text=[NSString stringWithFormat:@"Added: %@",theCellData.contentAddedDateTime];
NSString*type=theCellData.contentType;
NSLog(@"type is %@",type);
if ([type isEqualToString:@"Video"]) {
[cell.theCellImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Video icon.png",indexPath.row]] forState:UIControlStateNormal];
}
else if ([type isEqualToString:@"Audio"]) {
NSLog(@"Audio");
[cell.theCellImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Sound icon.png",indexPath.row]] forState:UIControlStateNormal];
}
else {
[cell.theCellImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"20.png",indexPath.row]] forState:UIControlStateNormal];
}
[cell.theCellImageButton addTarget:self action:@selector(imageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.theCellImageButton setTag:indexPath.row];
return cell;
这是崩溃日志
类型是音频 2013-06-14 16:09:50.071 ProductivoApp [6516:c503]音频 2013-06-14 16:09:50.076 ProductivoApp [6516:c503] - [NSNull isEqualToString:]:无法识别的选择器发送到实例0x125adc8 2013-06-14 16:09:50.079 ProductivoApp [6516:c503] * 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSNull isEqualToString:]:无法识别的选择器发送到实例0x125adc8 “
答案 0 :(得分:0)
您的字符串获取空值。因此在比较变量类型时显示错误
NSString*type=theCellData.contentType;// is null
if ([type isEqualToString:@"Video"]) //error at this line
答案 1 :(得分:0)
您要比较的字符串为空。尝试添加: //只有在不为空时才会这样做 if(string){
if([type isEqualToString:@" Video"]){
[cell.theCellImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Video icon.png",indexPath.row]] forState:UIControlStateNormal];
} else if([type isEqualToString:@" Audio"]){
NSLog(@"Audio");
[cell.theCellImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Sound icon.png",indexPath.row]] forState:UIControlStateNormal];
} 别的{
[cell.theCellImageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"20.png",indexPath.row]] forState:UIControlStateNormal];
}
}
这将确保不会发生空比较
答案 2 :(得分:0)
您的type
字符串不等于Audio
或Video
。当发生崩溃时,类型指的是NSNull
的实例。
有关详细信息,请尝试打印此文件,您将获得此NSNull
。
NSLog(@"%@", [type class]);