【发布时间】:2016-08-10 19:25:09
【问题描述】:
实现自定义表格视图单元格并在 dequeueReusableCellWithIdentifier 上收到以下错误,任何人都可以帮忙。
代码:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
//static DynamicTableViewCell *cell = nil;
var cell : DynamicTableViewCell?
var token: dispatch_once_t = 0
dispatch_once(&token) { () -> Void in
cell = tableView.dequeueReusableCellWithIdentifier("cell")
}
self.setUpCell(cell!, indexPath: indexPath)
return self.calculateHeightForConfiguredSizingCell(cell!)
}
【问题讨论】:
-
static DynamicTableViewCell 用词自相矛盾。这段代码根本无法工作。
dequeueReusableCellWithIdentifier外面的cellForRowAtIndexPath毫无意义。 -
我已经评论了那条线,但我没有使用它,我有一个相同的客观 c 版本,可以参考:-github.com/tjosten/iOS-UITableViewCell-with-dynamic-height我正在尝试用 swift 编写它
-
可能你应该只在tableView的方法cellForRowAtIndexPath中使用dequeueReusableCellWithIdentifier。对于自定义单元格,您应该在加载控制器时注册您的自定义类(例如在 viewDidLoad 中)
标签: swift