2011-07-28 70 views
0

我的表格中的每個單元格都有一個標籤,最多有三行,所以單元格高度取決於標籤的高度,我知道爲特定單元格返回高度的委託方法(NSIndexPath),但我需要獲取實際單元格爲了確定高度,如果我調用cellForRow:atIndexPath:in heightForCell :,它會無限循環,我猜cellForRow也會調用heightForCell。那麼有什麼辦法可以解決這個問題嗎?如何處理具有不同單元格高度的UITableView?

謝謝!

回答

0

您可以在heightForRow:delegate方法中使用字符串的NSString大小,例如

CGSize maxSize = CGSizeMake(300, 800); //max x width and y height 
NSString *cellTitle = @"Lorem ipsum"; 
UIFont *stringFont = [UIFont systemFontOfSize:14]; // use the same font your using on the cell 
CGSize cellStringSize = [myString sizeWithFont:stringFont constrainedToSize:maximumSize lineBreakMode: UILineBreakModeWordWrap]; 

這會給你一個CGSize,然後你可以使用這裏的高度並添加一點填充。您可以在這裏找到更多的信息:http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html

相關問題