在目标c中设置UIImageView时发生致命错误



你好,我有一个UIImageview,正在尝试设置以前保存在NSArray中的图像,然后将NSArray保存到NSMutableDictionary中。这是错误和代码。感谢您的帮助。

***由于未捕获异常"NSInvalidArgumentException"而终止应用程序,原因:"-[__NSCFConstantString_isSymbolImage]:无法识别的选择器发送到实例0x100e14318"以NSException 类型的未捕获异常终止

myAppDelegate *appDelegate = (myAppDelegate *)[UIApplication sharedApplication].delegate;
NSMutableArray *allKeys = [[appDelegate.localDataForIngestAndErrorVideos allKeys] mutableCopy];

for (NSString *key in allKeys) {
NSArray *object = (NSArray*)[appDelegate.localDataForIngestAndErrorVideos  objectForKey:key];
NSLog(@"id object ingest: %@",[object objectAtIndex:0]);
if ( [cell.Model.ContentItem.videoUploadStatus isEqualToString:@"ingest"])
{

cell.Model.ContentItem.mediaVideoUriHls = (NSURL*)[object objectAtIndex:2];
UIImage *tempImage = [[UIImage alloc]init];
tempImage = [object objectAtIndex:1];
[cell.mediaImageView setImage:tempImage];  <=== here crashes
}
}

错误[__NSCFConstantString _isSymbolImage]: unrecognized selector sent to instance是这样说的:让我们先翻译一下:__NSCFConstantStringNSString的内部(优化(类,所以只将其视为NSString因此,您有NSString实例,并尝试在其上调用_isSymbolImage方法。该方法是隐藏的,它是来自iOS SDK的隐藏调用。但NSString上不存在该方法,它不知道它,因此会出现错误。

看到崩溃线:

[cell.mediaImageView setImage:tempImage];

称为的内部方法是有道理的,您将tempImage视为UIImage

所以[object objectAtIndex:1]NSString而不是UIImage

现在,我建议为您的NSDictionaryappDelegate.localDataForIngestAndErrorVideos使用自定义模型。这比每次处理NSArray/NSDictionary时都不知道里面有什么要好。您还可以添加方法/计算属性,如-(NSURL)ingestURL等,以使代码更容易阅读。

旁注:

UIImage *tempImage = [[UIImage alloc]init];
tempImage = [object objectAtIndex:1];

alloc/init是无用的,因为您正在设置值。您执行alloc/init是徒劳的,因为您只是在之后忽略它。

相关内容

最新更新