我希望每个帖子在多行中显示完整标题,并且每个单元格根据文本标题字符数具有自己的自定义高度。我这样做了,但它不起作用。我认为每个对象都应该被独立调用。我怎样才能使这项工作?这是我的代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
PFObject *object1 = [PFObject objectWithClassName:@"Posts"];
NSString *string1 = [object1 objectForKey:@"text"];
NSLog(@"%@",string1);
CGSize theSize = [string1 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(265.0f, 9999.0f) lineBreakMode:UILineBreakModeWordWrap];
// numberOfTextRows is an integer.
numberOfTextRows = (round(theSize.height/14));
if ((indexPath.row== 0) || (numberOfTextRows <2)) {
return 44;
}
else {
return theSize.height +18;
}
}
注意:显示的 NSLog 显示 (null) 提前谢谢你..