您好,我有一個 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
}
}
uj5u.com熱心網友回復:
錯誤[__NSCFConstantString _isSymbolImage]: unrecognized selector sent to instance是這樣說的:讓我們先翻譯:__NSCFConstantString是 的內部(優化)類NSString,所以只需將其視為NSString
因此您有NSString實體并嘗試對其呼叫_isSymbolImage方法。該方法是隱藏的,它是來自 iOS SDK 的底層呼叫。但是該方法在 上不存在NSString,它不知道它,因此您得到了錯誤。
看到崩潰線:
[cell.mediaImageView setImage:tempImage];
呼叫的內部方法是有道理的,您將tempImage其視為UIImage.
[object objectAtIndex:1]aNSString不是 a也是如此UIImage。
現在,我建議為您的NSDictionary appDelegate.localDataForIngestAndErrorVideos. 這比每次處理NSArray/都不知道里面有什么要好。NSDictionary您還可以向其添加方法/計算屬性,例如-(NSURL)ingestURL等,以使您的代碼更容易和更具可讀性。
邊注:
UIImage *tempImage = [[UIImage alloc]init];
tempImage = [object objectAtIndex:1];
alloc/init 沒用,因為您正在設定值。你在做一個 alloc/init 是徒勞的,因為你在之后就忽略了它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/426064.html
標籤:IOS 目标-c uiimageview
