ios - 在自定义 UITableViewCell 中单击按钮时重新加载 UITableView

标签 ios swift uitableview

我的 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/

相关文章:

ios - 在 ViewController 顶部显示一条消息

iphone - 如何更改文本字段特定长度的按钮背景?

c# - 执行从 UITableView 到新 View Controller Xamarin 的 segue

ios - 使用 UIBezierPath 的圆角半径

ios - 如何在 swift (XCode 8) 中处理自定义 url 方案?

ios - 确定内容是否可滚动的属性(如果启用则不能)

swift - 简化 Swift 中的 If-Else If-Then 语句

ios - "Binary operator ' < ' cannot be applied to two CFIndex operands"- 从 ABMultiValue(地址簿)中选择一个电话号码

ios - swift 在 tableView 中选择一行的问题

ios - 在事务中调用当点击 UI 搜索栏并显示键盘时