Как изменить размер ячейки UITableView на размер NSString? Я пробовал следующее, и размер ячейки меняется немного, но не на всю высоту текста.ios: Изменение высоты ячейки до размера текста
у меня есть:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *str = [_recipe.ingredients objectAtIndex:indexPath.row];
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
UIFont *cellFont = [UIFont systemFontOfSize:14];
CGSize constraintSize = CGSizeMake(screenWidth-40, MAXFLOAT);
CGSize labelSize = [str sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height +35;
}
И:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.section == 0){
cell.textLabel.text = [_recipe.ingredients objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.textLabel.numberOfLines=1;
cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;
}
//cell.textLabel.text = [NSString stringWithFormat:@"Cell Row #%d", [indexPath row]];
return cell;
}
я получаю два предупреждения UILineBreakModeTailTruncated амортизируется.
Как получить слова для обертывания.
Да, реализуйте свои прокомментированные строки. – Wain
Я прибегал к написанию строки на фиктивном ярлыке и размером с этот ярлык, когда «официальные» методы не срабатывали по той или иной причине. –
Я понял, что изменил только обесцененное значение на NSLineBreakByWordWrapping – wwjdm