如何将 UITableView 单元格的大小更改为 NSString 的大小?我尝试了以下方法,单元格的大小略有变化,但没有达到文本的全高。
我有:
-(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 已贬值。
我如何让单词换行。