swift - 我无法快速通过协议传递值
问题描述
我需要将值从ScheduleViewController
确实选择行方法传递到MySchedularViewController
表格单元格。
这是我的协议
protocol ScheduleViewControllerDelegate {
func mySchedule(imgIcon: [String], proName: [String], proTime: [String])
}
从确实选择行方法中传递值
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
scheduleViewControllerDelegate?.mySchedule(imgIcon: ["hello"], proName: [programNameArray[indexPath.row]], proTime: [programTimeArray[indexPath.row]])
print("Row Selected")
}
在 myScheduleViewController 中获取协议
extension MySchedulerViewController: ScheduleViewControllerDelegate{
func mySchedule(imgIcon: [String], proName: [String], proTime: [String]) {
programImgUrlArray = imgIcon
programNameArray = proName
programTimeArray = proTime
print("Hello ")
DispatchQueue.main.async {
self.scheduleTableView.reloadData()
}
}
}
我为创建协议的 ViewController(ScheduleViewController) 创建了两个实例。它会导致任何问题吗?
解决方案
推荐阅读
- spring-mvc - 有没有办法根据我们单击的单选按钮重定向 jsp 页面
- swift - TableViewController 中自定义单元格的向下转换冲突
- typescript - 在 Visual Studio 代码中调试打字稿时如何查看控制台输出?
- discord.py - 使用其 id 获取不和谐语音通道
- php - PHP类中的SELECT查询
- r - 为 flexdashboard 绘制仪表图和串扰过滤
- html - 如何拥有全屏背景?
- javascript - Javascript比较数组中字典的键
- php - Codeigniter-Flashdata 会话
- javascript - 在 Vue 3 组合 Api 中触发监视功能