UITableViewCellのコンテンツの自動サイズ変更にこの一般的なアプローチを使用しています。そして、それは機能していません。私が得るのはこれだけです:
私のアプリはユニバーサルアプリで、ストーリーボード付きのiOS5を使用しています。.hファイルのコードは次のとおりです。
@interface SecondMasterViewController : UITableViewController
そしてこれらの2つの方法のために:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}
cell.textLabel.text = [self.mainCategories objectAtIndex:indexPath.row];
UIImage *myAwesomeCellImage;
myAwesomeCellImage = [UIImage imageNamed:
[NSString stringWithFormat:@"%@%@",
cell.textLabel.text,@".png"]];
cell.imageView.image = myAwesomeCellImage;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText = @"Go get some text for your cell.";
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 20;
}
私は何を間違えましたか?私はさまざまなアプローチを試しましたが、すべてが機能しません。
前もって感謝します!