我在viewdidload方法中創建了一堆圖像。這些圖像來自PFFile的解析,因此它們包含了我的圖像數據的fileURL。獲取圖像比文件URL更快
我的問題是,這兩行代碼正在顯着放緩我的應用程序並帶走了我的用戶體驗:
//get scene object
PFObject *sceneObject = self.scenes[i];
//get the PFFile and filetype
PFFile *file = [sceneObject objectForKey:@"file"];
NSString *fileType = [sceneObject objectForKey:@"fileType"];
//check the filetype
if ([fileType isEqual: @"image"])
{
//get image
NSURL *imageFileUrl = [[NSURL alloc] initWithString:file.url];
NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl]; ********** these
imageView.image = [UIImage imageWithData:imageData]; ********************* lines
}
如何獲得這個圖像/這些圖像(這是嵌套在一個for循環)更快速?我已經下載了包含PFFiles的PFObjects並將它們存儲在本地。
我想我真的不明白文件URL的操作方式。
謝謝。
這個偉大的工程!我必須改變dispatch_get_global(DISPATCH_PRIORITY_HIGH,0){到(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0),^ {和(dispatch_get_main_queue(){到dispatch_get_main_queue(),^ {除了這是一個非常快速的修復 – ian
謝謝@ user2792129爲編輯提示。很高興這是爲你工作。 –