需求: 取得相簿資訊後取得第一張圖片並為self.editImageView
賦值顯示.
問題: 但是我現在想在getImageForCollectionView
完全結束後來為self.editImageView
賦值,那麼問題來了,我如何判斷getImageForCollectionView
函數已經進行完畢?
- (void)getImageForCollectionView{
_library = [[ALAssetsLibrary alloc] init];
self.photos = [NSMutableDictionary dictionary];
[_library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
NSMutableArray *array = [NSMutableArray array];
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
[array addObject:result];
}
}];
[self.photos setValue:array forKey:[group valueForProperty:@"ALAssetsGroupPropertyName"]];
}
} failureBlock:^(NSError *error) {
}];
}
將耗時的操作放在非主執行緒中,需要UI更新的放在主執行緒中。
EDIT: