私は2つのView Controllerで同じコードを使用しています(それらは同じクラスを実装しており、ダウンロードするURLが変更されます)、ある場合には画像が正しく表示され、別の場合には空のセルが表示されます。
これが私のコードです:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier=@"MyCell";
//this is the identifier of the custom cell
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
tableView.backgroundColor=[UIColor clearColor];
tableView.opaque=NO;
tableView.backgroundView=nil;
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSLog(@"Image url is:%@",[images_url objectAtIndex:indexPath.row]);
NSURL *url_image=[NSURL URLWithString:[images_url objectAtIndex:indexPath.row]];
cell.myimage.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:url_image]];
return cell;
}
私が言ったように、同じクラスを実装する2つのView Controllerがあります。ビューでは、ロードされた URL はフラグの値に応じて設定されます。コントローラ A を開くと画像が表示されませんが、ビュー B を開くと画像が表示されます。挿入した NSLog で確認できるので、どちらの URL も正しいです。
何が問題なのですか?