[英]Custom table cell without dequeueReusableCellWithIdentifier in Swift
[英]Swift: Create static custom cell without dequeueReusableCellWithIdentifier
早上好,我需要在不使用dequeueReusableCellWithIdentifier的情况下在我的自定义tableViewController中实例化名为“ CustomCell”的自定义单元格,因为该功能由于某些交互作用(我认为目前无需描述)在滚动时错误地替换了我的单元格(即,最后一个单元格与第一个单元格交换,依此类推)。
所以我的代码是这样的:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> CustomCell {
// NEW VERSION HERE ---------
var cell = CustomCell()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.userInteractionEnabled = true
cell.clipsToBounds = false
// OLD VERSION HERE ---------
//var cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as! CustomCell
// Configure my cells....
return cell
}
所以这个版本(没有dequeueReusableCellWithIdentifier)是我在单元格的位置上没有更多的问题,但是我不能单击/点击或简单地将我的自定义项“使用”到单元格中。
例如,我有一个像这样的DatePicker:
var dynamicPicker = UIDatePicker(frame: CGRectMake(0, 0, self.frame.width, 192.0))
dynamicPicker.date = date_
dynamicPicker.addTarget(self, action: "pickerChanged:", forControlEvents: UIControlEvents.ValueChanged)
view.addSubView(dynamicPicker)
而且我什至无法更改日期,我无法轻按,或者通常我无法与之互动。 似乎“ userInteractionEnabled为false”,但事实并非如此。
预先谢谢大家,马可先生。
每个UITableView示例都使用dequeueReusableCellWithIdentifier是有原因的。 这就是使用表视图的方式。
看来您实际上要解决的问题是“最后一个单元交换与第一个单元交换,依此类推”。 也许那应该是您的问题。
在单元配置中(出队后...),重置所有单元数据。 您能否进一步说明使用出队的问题是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.