如何处理具有不同单元格高度的UITableView?
我的表格中的每个单元格都有一个标签,最多三行,因此单元格高度取决于标签的高度,我知道返回特定单元格高度的委托方法(NSIndexPath),但我需要按顺序获取实际单元格来确定高度,如果我在 heightForCell: 中调用 cellForRow:atIndexPath: ,它会无限循环,我猜 cellForRow 也会调用 heightForCell 。那么我有什么办法可以处理这个问题吗?
谢谢!
each cell in my table has a label, with maximum three lines, so the cell height depends on the label's height, I know the delegate method that returns height for a specific cell(NSIndexPath), but I need to get the actual cell in order to determine the height, and if I call cellForRow:atIndexPath: in heightForCell:, it loops infinitely, I guess cellForRow also calls heightForCell. So is there any way I can handle this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 heightForRow: 委托方法中使用 NSStrings 大小作为字符串,例如
这将为您提供一个 CGSize,然后您可以使用此处的高度并添加一点填充。您可以在此处找到更多信息: http:// /developer.apple.com/library/ios/#documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html
蒂姆
You can use NSStrings size for string in the heightForRow: delegate method e.g.
This will give you a CGSize you can then use the height from here and add a little padding. You can find more information here: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html
Tim
使用
NSString
的– sizeWithFont:constrainedToSize:lineBreakMode:
(您可以在此门户上找到更多相关信息)或使用包含每个indexPath
高度的数组> 如本示例所示(SectionInfo 类)http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html。Use
– sizeWithFont:constrainedToSize:lineBreakMode:
ofNSString
(you can find more on this on this portal) or use an array containing height for everyindexPath
as shown in this example (SectionInfo class) http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html.