尝试创建一个委托. (我假设你知道,如果不看看有关委托和协议的苹果文档)
所以我建议的想法是创建一个将在UITableViewController(或符合UITableViewDelegate协议的UIViewController)中实现的函数
首先尝试在CustomCell.swift文件之上添加协议.
protocol CustomCellUpdater: class { // the name of the protocol you can put any func updateTableView() }
然后在CustomCell.swift中:
weak var delegate: CustomCellUpdater? func yourFunctionWhichDoesNotHaveASender () { ... delegate?.updateTableView() }
在你的UITableViewController(或等效的)之后
func updateTableView() { tableView.reloadData() // you do have an outlet of tableView I assume }
最后,使您的UITableview类符合CustomCellUpdater协议
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "yourIdentifier",for: indexPath) as! YourTableViewCell cell.delegate = self }
理论上它应该有效.如果我错过任何东西,请告诉我
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。