2013-03-06 70 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小區中心另一視圖。