0
以下のコードを使用して、セルの高さをセルのテキストのサイズに自動的に合わせます。現時点では動作しますが、セルの上部と下部に空白を追加します(たとえば、10行の場合は前後4行ですが、200行の場合はスクリーンショットのように40行上と下になります)あなたの高さを計算し、実際のラベルにしたとき、2つの異なるフォントサイズを使用しているように、痛みのビットになる!)IPhoneテキスト入力に基づいてセルを自動サイズ変更する際の問題
- (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];
}
AssessObject *newObj1;
newObj1=[totalArray objectAtIndex:indexPath.section];
cell.textLabel.text = newObj1.routeImage;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
AssessObject *newObj1;
newObj1=[totalArray objectAtIndex:indexPath.section];
NSString *cellText = newObj1.routeImage;
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:16.0];
CGSize constraintSize = CGSizeMake(190.0, CGFLOAT_MAX);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height;
}