1

cell.imageView は初回読み込み時に正しく表示されます。UITableViewCell が画面から外れて再びオンになった後、突然 cell.imageView のサイズがセルの高さを埋めるように変更されました。セルが強調表示された状態に設定されている場合も同じです。cell.imageView は、インターフェイス ビルダーで作成されます。

 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSDictionary *dataType = [self.dataTypes objectAtIndex:indexPath.row];
    [cell.imageView setImageWithURL:[NSURL URLWithString:[dataType valueForKey:@"imageURL"]]
                   placeholderImage:nil];

    cell.titleLabel.text = [data valueForKey:@"name"];
    cell.descriptionLabel.text = [data valueForKey:@"info"];

    return cell;
}
4

2 に答える 2

0

以下の回答を試して、必要な変更を加えてください

https://stackoverflow.com/a/15331306/1713478

この回答に追加

cell.titleLabel.text = [data valueForKey:@"name"];
cell.descriptionLabel.text = [data valueForKey:@"info"];

SimpleTableCellCustomCellに変更し、imageURLに画像の URL を入力する だけです

その他の必要な変更を行います。

あなたの問題が解決するかもしれません。

于 2013-04-10T05:49:05.337 に答える
0

Pratik の回答にインスパイアされたので、インターフェイス ビルダーから UIImageView を削除し、その場で作成することにしました。これは期待どおりに機能しますが、なぜ違うのかわかりません。おそらくIBの制約と関係があります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSDictionary *data = [self.dataTypes objectAtIndex:indexPath.row];

    UIImageView *thumb = [[UIImageView alloc]initWithFrame:CGRectMake(11, 10, 52, 74)];
    [thumb setImageWithURL:[NSURL URLWithString:[data valueForKey:@"imageURL"]]
                   placeholderImage:nil];
    [cell addSubview:thumb];
    [thumb release];

    cell.titleLabel.text = [data valueForKey:@"name"];
    cell.descriptionLabel.text = [data valueForKey:@"info"];

    return cell;
}
于 2013-04-10T09:17:54.947 に答える