이것은 내 첫 번째 질문으로 초보자가되어서 실례합니다.인터넷에서 이미지 가져 오기 CollectionView
인터넷에서 다운로드 한 이미지를 보여주는 CollectionView로 작업하고 있습니다. 문제는 비동기 적으로 시도 할 때 나타납니다.
@interface myViewController
{
NSArray *ArrayOfSections
}
@end
-(void)viewDidLoad{
[self performSelectorInBackground:@selector(refreshImages) withObject:nil];
}
-(void)refreshImages{
... //Get information from the net
NSArray internetInfo = ...;
[self performSelectorOnMainThread:@selector(refreshCollectionView:) withObject:internetInfo waitUntilDone:NO];
}
-(void)refreshCollectionView:(NSArray tempArray){
ArrayOfSections = tempArray;
}
이 코드는 작동하지 않습니다. ArrayOfSections에 저장된 정보가 올바른지 이중으로 확인했지만 빈 CollectionView를 보여줍니다.
또한 내가 동기식으로 수행하면 (viewDidLoad 만 변경).
-(void)viewDidLoad{
[self refreshImage];
}
모든 것이 정상적으로 작동합니다. 나는 바나나로 갈거야. 제발 도와주세요
예! 정말 고맙습니다! 비록 스레딩 문제 였지만 collectionView를 다시로드하려고 시도했지만 데이터는 다시로드하지 않았습니다. 열쇠는 [self.collection reloadData]입니다. –