2013-03-06 69 views
0

您好我正在尝试根据textlabel和detailtextlabel动态更改我的行高度。基于文本标签和细节文本标签的行高 - 物镜c

以下是我的代码:

NSString *title = [NSString stringWithFormat:@"%@%@%@",_note.committeeStaffName,@" - ",_note.dateCreated]; 
    cell.textLabel.text = title; 
    cell.detailTextLabel.text = _note.note; 

我试图调整基础上,为textLabel和detailTextLabel表的行的高度。 textLabel不会超过一行。 detailTextLabel包含不同长度的大文本。我已经阅读了委托方法heightForRowAtIndexPath的几个例子,但是他们都没有清楚地说明在方法heightForRowAtIndexPath中应该做什么以及在cellForRowAtIndexPath中应该执行什么代码。任何人都可以清楚地解释一下代码应该在两个方法heightForRowAtIndexPath和cellForRowAtIndexPath中进行调整,以便根据包含textLabel和detailTextLabel的内容调整表格行的高度。

+0

[根据文本量更改UITableViewCell高度]的可能重复(http://stackoverflow.com/questions/9827126/change-the-uitableviewcell-height-according-to-amount-of-text) – CodaFi 2013-03-07 00:34:47

回答

0

我想给你解决你的问题的想法。希望它能帮助你。

-(CGFloat)getLabelHeightForIndex:(NSString*)strTemplate{ 
CGSize maximumSize = CGSizeMake(tblView.frame.size.width-50, 20000); 
NSString* result = [strTemplate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
strTemplate = result; 
CGSize labelHeighSize = [strTemplate sizeWithFont: [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0] constrainedToSize:maximumSize lineBreakMode:NSLineBreakByWordWrapping]; 
return labelHeighSize.height; 

}
应该使用上述方法来得到任一个标签,即为textLabel或defaulttestLabel的高度然后管理上的其他中的tableView小区中心另一视图。