Я могу отображать содержимое ячейки в таблице, а также Wordwrap, чтобы отобразить сообщение полностью. Но я заметил, что если содержание больше высоты, то оно становится комковатым. Как динамически увеличить высоту ячейки, если содержимое слишком велико. Поскольку я получаю данные из URL-адреса, длина меняется, поэтому я не хочу жестко кодировать высоту, а хочу изменять ее в соответствии с длиной содержимого.
Код, который я пробовал до сих пор, находится под:
- (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;
}