繁体   English   中英

Swift:如何将wilDisplayCell分配给特定的自定义寄存器单元?

[英]Swift: How do I assign wilDisplayCell to specific custom register cell?

我在tableViewController中有两个注册单元格,但其中一个有动画功能(显示/隐藏),所以当我注册第二个单元格并将其带到tableview时,我在tableview的wilDisplayCell函数中出现错误, 如何判断willDisplayCell仅适用于一种类型的细胞?

我的2个自定义寄存器单元: //注册自定义单元

self.tableView.registerNib(UINib(nibName: "NormalPostTableViewCell", bundle: nil), forCellReuseIdentifier: "NormalPostCell")
self.tableView.registerNib(UINib(nibName: "VideoTableViewCell", bundle: nil), forCellReuseIdentifier: "VideoCell")

覆盖一种细胞类型的功能:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        (cell as! NormalPostTableViewCell).watchFrameChanges()
}

错误:

无法将'app.VideoTableViewCell'(XXXXXX)类型的值转换为'app.NormalPostTableViewCell'(XXXXXX)。

错误Scre​​eshot: 在此输入图像描述

方法2:

另一种方法(2)我尝试将willDisplayCell cell:设置为willDisplayCell cell: NormalPostTableViewCell并删除override

func tableView(tableView: UITableView, willDisplayCell cell: NormalPostTableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        (cell as NormalPostTableViewCell).watchFrameChanges()
}

并且方法2导致此错误:

方法'tableView( :willDisplayCell:forRowAtIndexPath :)'与Objective-C选择器'tableView:willDisplayCell:forRowAtIndexPath:'与方法'冲突'tableView( :willDisplayCell:forRowAtIndexPath :)'来自超类'UITableViewController'与相同的Objective-C选择器

如何在不干扰其他单元格的情况下修复此问题并仅将此函数应用于NormalPostTableViewCell类?

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    if let postCell = cell as? NormalPostTableViewCell  {
       postCell.watchFrameChanges()
    }
}        

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM