我有一些可调用的电文,是动态的,有些其他物体应纵向集中。
此时此刻,我计算了UITextView的高度,并把它用作确定一切的参考。
问题一是,有时它计算出错误和“价格”总是在中上端? 上诉人,如发卷的20%,因此,牢房将再次站起来。
Is there a way to get the higeht of the cell? And why does it calculate wrong? It also cuts the UITextView in half when this problem appear?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
CGSize size;
NSString *text;
/* Height of each cell */
text = @"Some different lengths of text";
size = [text sizeWithFont:[UIFont fontWithName:@"TrebuchetMS" size:17] constrainedToSize:CGSizeMake(theTableView.bounds.size.width - 260, 800) lineBreakMode:UILineBreakModeWordWrap];
float totalSize = size.height + 10;
if (totalSize < 120) {
return 120;
} else {
return totalSize;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
CGSize size;
NSString *text;
float totalSize;
/* Height of each cell */
text = @"Some different lengths of text";
size = [text sizeWithFont:[UIFont fontWithName:@"TrebuchetMS" size:17] constrainedToSize:CGSizeMake(theTableView.bounds.size.width - 260, 800) lineBreakMode:UILineBreakModeWordWrap];
if (size.height + 10 < 120) {
totalSize = 120;
} else {
totalSize = size.height + 10;
}
}
/* Createing a new Cell */
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
/* Create the text Label */
textView = [[[UITextView alloc] initWithFrame: CGRectMake(90,35,theTableView.bounds.size.width - 260 , totalSize)] autorelease];
[cell.contentView addSubview:textView];
textView.tag = TEXT_LABEL_TAG;
textView.backgroundColor = [UIColor clearColor];
textView.textColor = [UIColor blackColor];
textView.font = [UIFont fontWithName:@"TrebuchetMS" size:17];
textView.editable = NO;
textView.userInteractionEnabled = NO;
/* Create price Label */
priceLabel = [[[UILabel alloc] initWithFrame: CGRectMake(theTableView.bounds.size.width - 225, (totalSize/2) - (35/2), 120 , 35)] autorelease];
[cell.contentView addSubview:priceLabel];
priceLabel.tag = PRICE_LABEL_TAG;
priceLabel.textAlignment = UITextAlignmentRight;
priceLabel.backgroundColor = [UIColor clearColor];
priceLabel.textColor = [UIColor redColor];
priceLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:22];