当每个表格视图单元格具有不同的高度时,如何避免 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];
}