我希望每个帖子显示完整的标题在多行和每个单元格有自己的自定义高度根据文本标题字符数。我这样做了,但它不起作用。我认为每个对象都应该独立调用。我怎么才能让它工作呢?下面是我的代码:
- (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显示(空)预先感谢。
发布于 2013-03-04 01:35:00
这是我的解决方案。根据您的需要进行自定义。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText;
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
if (searchDisplayController.active && [searchResults count]) {
cellText = [searchResults objectAtIndex:indexPath.row];
} else {
cellText = [detailPeriodsContent objectAtIndex:indexPath.row];
}
UIFont *cellFont = [UIFont systemFontOfSize:14];
CGSize constraintSize = CGSizeMake(screenWidth-40, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 35;
}https://stackoverflow.com/questions/12693547
复制相似问题