我正在尝试将数据从父 View Controller 发送到 subview Controller ,每当我覆盖 performSegue 方法时,数据都会加载到弹出 View ,如下所示:
我已经通过 didSelectRowAt indexPath 方法将弹出 View 添加到主视图,我使用了协议(protocol)方法,但它没有加载数据。
我的父 View Controller 代码如下所示:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as! TableViewCell
cell.customInit(noticeTitle: notificatonData[indexPath.row].notice_title,noticeDiscripetion: notificatonData[indexPath.row].notice_desc)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopUpViewController")
self.addChildViewController(popOverVC)
popOverVC.view.frame = view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParentViewController: self)
performSegue(withIdentifier: "goToPopUpView", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? PopUpViewController{
destination.notificationfianlData = notificatonData[(tableView.indexPathForSelectedRow?.row)!]
}
}
最佳答案
你应该使用 segue 或 child
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "goToPopUpView", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? PopUpViewController{
destination.notificationfianlData = notificatonData[(tableView.indexPathForSelectedRow?.row)!]
}
选择segue线和
在popupVC中选择主视图,并使其背景色透明
关于swift - 从父 View Controller 向 subview Controller 发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49004679/