1

以下のコードのように、カテゴリでUItableViewcellのlayoutSubviewsメソッドを使用したとき

@implementation UITableViewCell (forimage)

- (void)layoutSubviews{
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0, 0, 50, 50);
}

@end

以下のコードを使用してセルを描画すると、textLabelが消えてしまいました。なぜそうなったかは誰にも分かります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    RadioInfo *radioinfo = [radios objectAtIndex:indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@",radioinfo._name];

    if(!radioinfo._logo){
        if(self.tableView.dragging == NO && self.tableView.decelerating == NO){
            [self startPicDownload:radioinfo forIndexPath:indexPath];
        }

        cell.imageView.image = [UIImage imageNamed:@"1.jpg"];
    }
    else {
        cell.imageView.image = radioinfo._logo;
    }

    return cell;
}
4

1 に答える 1

6

やりたいことは、UITableViewCell の layoutSubviews メソッドの動作に追加することであり、置き換えることではありません。

動作に適切に追加するには、上記のようにセルをサブクラス化し、独自のレイアウトを実行しますが、メソッドの一番上に [super layoutSubviews] を追加して、セル独自の基本的なレイアウトが最初に実行されるようにします。

于 2011-06-30T09:29:08.253 に答える