gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:59:17 25 4
gpt4 key购买 nike

我的 tableViewController 中有两个已注册的单元格,但其中一个具有动画功能(显示/隐藏),因此当我注册第二个单元格并将其带到 tableview 时,我在 wilDisplayCell tableview 的功能,如何告诉 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()
}

错误:

Could not cast value of type 'app.VideoTableViewCell' (XXXXXX) to 'app.NormalPostTableViewCell' (XXXXXX).

错误截图: enter image description here

方法二:

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

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

而方法 2 导致此错误:

Method 'tableView(:willDisplayCell:forRowAtIndexPath:)' with Objective-C selector 'tableView:willDisplayCell:forRowAtIndexPath:' conflicts with method 'tableView(:willDisplayCell:forRowAtIndexPath:)' from superclass 'UITableViewController' with the same Objective-C selector

如何在不干扰其他单元格的情况下解决此问题,并且只将此函数应用于 NormalPostTableViewCell 类?

最佳答案

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

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

关于ios - Swift:如何将 wilDisplayCell 分配给特定的自定义寄存器单元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31360350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com