我正在尝试动态重新计算包含UITextView
的单元格的高度。单元格的高度取决于高度UITextView。
下面的源代码重新计算表格中每个单元格的高度。这是来自NSDictionary
的一些文字。重新计算完所有高度后,我重新加载我的表视图,其中包含数组heightCells的新高度;
UITextView *tempTextView = [[UITextView alloc] init];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:16.0];
[tempTextView setFrame:CGRectMake(10, 63, 300, 9999)];
[tempTextView setFont:font];
NSString *str = [d valueForKey:@"definition"]; // set long text
tempTextView.text = str;
CGRect frame = tempTextView.frame;
frame.size.height = tempTextView.contentSize.height + 20.0;
tempTextView.frame = frame;
[tempTextView sizeToFit];
int height = tempTextView.frame.size.height + 150.0; // set padding 150.0 px
[heightCells addObject:[NSNumber numberWithFloat:height]];
UITableView
方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [[heightCells objectAtIndex:indexPath.row] floatValue];
}
在没有视网膜显示器上,一切正常,高度重新计算正确,但在视网膜显示器上我有重新计算的问题。我知道视网膜而不是视网膜有一个320x480点视图,它不应该影响重新计算。但就我而言,这就出现了。
请看下面的截图。正如您在屏幕截图中看到的那样,分享按钮后的底部填充不同于视网膜而不是视网膜显示。我不知道这个问题是哪种。
感谢您的帮助!