1
我可以在表格中显示单元格内容,也可以Wordwrap它来完全显示消息。但我注意到,如果内容比高度多,则会变得很团结。如果内容太大,如何增加动态提高单元格的大小。由于我从url中检索数据,所以长度会有所不同,所以我不想对高度进行硬编码,但希望根据内容长度对其进行更改。动态调整tableView单元格的高度
,我已经试过到目前为止是为下的代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *person = [myPeople objectAtIndex:[indexPath row]];
NSString *personName = [person valueForKey:@"text"];
NSString *cellText = personName;
UIFont *cellFont = [UIFont fontWithName:@"Helvetica-neuve" size:21.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
int buffer = 70;
return labelSize.height + buffer;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [commentView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 6;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-neuve" size:21.0];
[cell.textLabel setMinimumFontSize:13.0];
[cell.textLabel setAdjustsFontSizeToFitWidth:NO];
}
NSDictionary *person = [myPeople objectAtIndex:[indexPath row]];
NSString *personName = [person valueForKey:@"text"];
cell.textLabel.text = personName;
return cell;
}
但我想调整单元格高度 – iDev
对不起,我错了。我看到你已经在使用这种方法。当你用相同的方法钩住willDrawCell会发生什么。 –