我的 TableView 单元格中有一个按钮,我想重新加载整个 View ,它是一个基本 Controller 。
这个类是我要重新加载的(刷新,也许记忆一下 View Controller )。
import UIKit
class TableVC: BaseController, DBDelegate, PLDelegate {
@IBOutlet weak var tableViewDB: UITableView!
}
这是我必须做的地方:
import UIKit
class DailySpeakingLesson: UITableViewCell {
}
最佳答案
为此使用委托(delegate)。
在 tableView(_:cellForRowAt:)
中为自定义单元格设置委托(delegate),然后在委托(delegate)函数内调用 tableViewDB.reloadData()
。
表VC
class TableVC: BaseController, DBDelegate, PLDelegate, DailySpeakingLessonDelegate {
@IBOutlet weak var tableViewDB: UITableView!
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let dailySpeakingLesson = tableView.dequeueReusableCell(withIdentifier: "cellId") as! DailySpeakingLesson
dailySpeakingLesson.delegate = self
return dailySpeakingLesson
}
func dailySpeakingLessonButtonPressed() {
tableViewDB.reloadData()
}
}
每日口语课
class DailySpeakingLesson: UITableViewCell {
weak var delegate: DailySpeakingLessonDelegate?
@IBAction func buttonPressed() {
delegate?.dailySpeakingLessonButtonPressed()
}
}
委托(delegate)
protocol DailySpeakingLessonDelegate: class {
func dailySpeakingLessonButtonPressed()
}
关于ios - 在自定义 UITableViewCell 中单击按钮时重新加载 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46199727/