メソッドが完成したらコードを開始したい。サーバーから画像の配列をロードし、それらの画像を作成したセルのImageViewに追加するUICollectionViewがあります。これは、私のコードです。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"cellID";
insightCell *myCell = (insightCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
myCell.tag = [[[objectiveGov n_insights] objectAtIndex:indexPath.item]integerValue];
imgTag = ((UICollectionView *)myCell).tag;
//This is the Method I want to run "ObjectiveGov is the NSObject which has my Method inside "arrayImages" which is separate to the view controller this UICollectionView is in.
[objectiveGov arrayImages];
//Possible if statement here, that records when the method above is finished.
myCell.insightImageView.image = [theInsightImage objectAtIndex:indexPath.item];
return myCell;
}
したがって、メソッド[objectiveGov arrayImages];
が終了したら、を実行する必要がありmyCell.insightImageView.image
ます。これを行う方法はありますか?メソッドの最後に投稿するNSNotificationCenterを作成しようとしましたが、UICollectionViewが割り当てられたときにUICollectionViewCellメソッドが開始されるため、これは機能しませんでした。何か案は?ありがとう!
ArrayImagesメソッドコードの編集:
+(void)arrayImages
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"postArrayImages" object:nil];
[[NSUserDefaults standardUserDefaults] synchronize];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/api/insights/get/",URL_ROOT]];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSString *imageString = [NSString stringWithFormat:@"%d",[viewInsightViewController imgTag]];
NSURLRequest *request = [httpClient requestWithMethod:@"GET" path:imageString parameters:nil];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *dictionInsight = [JSON valueForKey:@"results"];
NSArray *insightArray = [dictionInsight valueForKey:@"images"];
NSString *fileName = [dictionInsight valueForKey:@"filename"];
if (fileName == (id) [NSNull null])
{
//URL incase server file doesnt contain image.
nineArray = [NSString stringWithFormat:@"http://url.co.uk/images/logo.png"];
}else {
nineArray = [insightArray valueForKey:@"96"];
}
insightURL = [NSURL URLWithString:nineArray];
if (insightURL != nil) {
NSURLRequest *requestImage = [NSURLRequest requestWithURL:insightURL];
AFImageRequestOperation *imageOperation = [AFImageRequestOperation imageRequestOperationWithRequest:requestImage imageProcessingBlock:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
if (requestImage != nil) {
insightImages = image;
[arrayOfImages addObject:insightImages];
}
} failure:nil];
[imageOperation start];
}