开发者

Stop image expanding in multiline table row?

I'm having problems implementing a table row that allows text to wrap to multiple lines, and also has an image on the left, a开发者_StackOverflownd a disclosure accesssory on the right.

The multiline text is fine but the imageView expands to the right when there is more than one line of text. I want images in all rows to be the same size. I've tried setting the autoresizingMask to UIViewAutoresizingNone but this doesn't seem to work.. Do I need to use the contentView, or a nib file?

Any help/example code appreciated!


If all off your images are different size then you should think of adding a ImageView as Subview to cell. Keep Labels depending on the Imageview.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;

    UIImageView *cellImage;
    UILabel *label;
    UILabel *detailLabel;

    cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; //Create cell
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];

        cellImage = [[[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 44, 44)] autorelease];


        label = [[[UILabel alloc] initWithFrame:CGRectMake(55, 4, 260, 20)] autorelease];
        label.font = [UIFont boldSystemFontOfSize:15.0];
        label.tag=25;

        detailLabel = [[[UILabel alloc] initWithFrame:CGRectMake(55, 25, 260, 15)] autorelease];
        detailLabel.font = [UIFont systemFontOfSize:13.0];
        detailLabel.tag=30;

        [cell.contentView addSubview:cellImage];
        [cell.contentView addSubview:label];
        [cell.contentView addSubview:detailLabel];
        cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;

    }
    else
    {
        cellImage = (UIImageView *)[cell.contentView viewWithTag:20];
        label = (UILabel *)[cell.contentView viewWithTag:25];
        detailLabel = (UILabel *)[cell.contentView viewWithTag:30];
    }
    cell.image = [arrayContainingImages objectAtIndex:indexPath.row];
    label.text =[arrayContaininglabeltext objectAtIndex:indexPath.row];
    detailLabel.text=[arrayContainingDetailLabelText objectAtIndex:indexPath.row];
    return cell;
}


pls see Stop image expanding in multiline table row? #2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜