Far*_*had 3 xcode uitableview ios swift
我在tableViewController中有两个已注册的单元格,但其中一个有动画功能(显示/隐藏),所以当我注册第二个单元格并将其带到tableview时,我在wilDisplayCelltableview的功能中出错,我怎么能告诉willDisplayCell仅适用于一种类型的细胞?
我的2个自定义寄存器单元: //注册自定义单元
self.tableView.registerNib(UINib(nibName: "NormalPostTableViewCell", bundle: nil), forCellReuseIdentifier: "NormalPostCell")
self.tableView.registerNib(UINib(nibName: "VideoTableViewCell", bundle: nil), forCellReuseIdentifier: "VideoCell")
Run Code Online (Sandbox Code Playgroud)
覆盖一种细胞类型的功能:
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as! NormalPostTableViewCell).watchFrameChanges()
}
Run Code Online (Sandbox Code Playgroud)
错误:
无法将'app.VideoTableViewCell'(XXXXXX)类型的值转换为'app.NormalPostTableViewCell'(XXXXXX).
错误Screeshot:

方法2:
我尝试的另一种方法(2)是设置willDisplayCell cell:为NormalPostTableViewCell这样并删除override:
func tableView(tableView: UITableView, willDisplayCell cell: NormalPostTableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as NormalPostTableViewCell).watchFrameChanges()
}
Run Code Online (Sandbox Code Playgroud)
并且方法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()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2374 次 |
| 最近记录: |