-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
}
cell.textLabel.text = timelabel.text;
cell.detailTextLabel.text = commentTextView.text;
}
//int x = cell.commentTextView.frame.size.height;
}
cell.detailTextLabel.textAlignment = UITextAlignmentLeft;
cell.textLabel.textAlignment = UITextAlignmentLeft;
return cell;
}
我需要根据在文本视图中输入的注释长度来扩展单元格大小:详细信息显示在textTextLabel中的'commentTextView。
但是textLable(时间文本)的差异,它不会随着detailTextLabel
该怎么办?
答案 0 :(得分:1)
这一点总是很难做到,因为你需要实现这样的高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *myLabel = "Hello World";
CGSize labelSize = [[myLabel sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(160,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height;
}
答案 1 :(得分:1)
您可以使用tableview的- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath
委托方法来执行此操作,例如: -
- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize lblSize ;
NSString *lblString ;
lblString = [[[dataSourceArray objectAtIndex:indexPath.row] valueForKey:@"aKey"];
lblSize = [self getLebalSize:CGSizeMake(180, 9999) aLebalText:lblString aFont:[UIFont systemFontOfSize:15]];
return lblSize.height + 10 ;
}
//getting labelsize
- (CGSize) getLebalSize : (CGSize) maxSize aLebalText : (NSString *) lebalText aFont : (UIFont *) font
{
CGSize expectedLabelSize = [lebalText sizeWithFont:font constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
return expectedLabelSize;
}