0

当每个表格视图单元格具有不同的高度时,如何避免 UITableViewCell 中包含的 UIImageView 被扩展?根据 UILabel 的文本长度,我每行的高度都是可变的。当 UITableViewCell 的高度增加时,图像视图s image height also increases. How to keep image view的帧常数?

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
       NSString *text = [self.myArray objectAtIndex:indexPath.row];

        if(text.length!=0)
        {    

        CGSize constraint = CGSizeMake(212, LONG_MAX);

        CGSize size = [text sizeWithFont:[UIFont fontWithName:@"Arial" size:14.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

        CGFloat height = size.height;

      return (71.0 + height); //this gives the row height
        }
}


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

    MyXYZ *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyXYZ" owner:nil options:nil];
        for (id currentObject in topLevelObjects) {
            if ([currentObject isKindOfClass:[MyXYZ class]]) {
                cell = (MyXYZ *)currentObject;
]                break;
            }
        }
    }  

 ((HJManagedImageV *)cell.myImageView).url = [NSURL URLWithString:myImageUrl]; 
}   
4

3 回答 3

0

Create a custom cell in which you can keep the frame of the UIImageView constant. This will help it to remain the same throughout the tableView cells even if you vary the height of various cells

于 2012-09-24T10:26:54.910 回答
0
try this

[cell.contentView addSubview:imageview];
于 2012-09-24T10:32:13.270 回答
0

contentMode图像视图的属性设置为适当的值,以禁止在图像视图中缩放图像,并且不关心图像视图本身的大小。

于 2012-09-24T10:32:33.853 回答