私のアプリでは PSCollectionView を使用しますが、デリゲート メソッドは呼び出しません。私はそうしました:
- JSONファイルを読みました
- この JSON を解析して、名前と画像の URL を取得します
- デバイスを画像の URL に接続して、この質問の最後にあるコードで幅と高さを取得します
この操作の後、デリゲート メソッドを呼び出して PSCollectionViewCell の数を取得し、各セルの高さを定義し、セルに画像と名前を入力する必要があります。デリゲート メソッドを実装しましたが、実行されません。私の問題は、セルの特性を作成して定義したいときに、セルを埋めるための情報を含む配列がまだ空であるためだと思います。どうすればこれを解決できますか?
コード:
- (void) loadImageFromWeb:(NSString *)urlImg forName:(NSString*)name {
NSURL* url = [NSURL URLWithString:urlImg];
//NSURLRequest* request = [NSURLRequest requestWithURL:url];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSString *authCredentials =@"reply:reply";
NSString *authValue = [NSString stringWithFormat:@"Basic %@",[authCredentials base64EncodedStringWithWrapWidth:0]];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * data,
NSError * error) {
if (!error){
image = [[UIImage alloc] initWithData:data];
imageWidth = image.size.width;
imageHeight = image.size.height;
imgWidth = [NSString stringWithFormat:@"%f", imageWidth];
imgHeight = [NSString stringWithFormat:@"%f", imageHeight];
self.dictWithDataForPSCollectionView = @{@"title": name,
@"width": imgWidth,
@"height": imgHeight};
[self.arrayWithData addObject:self.dictWithDataForPSCollectionView];
NSLog(@"DATA ARRAY: %@", self.arrayWithData);
} else {
NSLog(@"ERRORE: %@", error);
}
}];
}
誰でもこの問題を解決するのを手伝ってもらえますか? ありがとうございました!