[英]Swift - Pass data from table view xib file to view controller
I am trying to pass data from my table which is a xib file to a view controller but for some reason, the code is not working and throwing an error. 我正在尝试将数据从xib文件的表传递给视图控制器,但是由于某种原因,代码无法正常工作并引发错误。 I have also browsed the internet, yet not got the solution. 我也浏览了Internet,但没有找到解决方案。
viewDidLoad Function viewDidLoad函数
override func viewDidLoad() {
super.viewDidLoad()
dataPass()
self.navigationItem.title = "Landlord List"
propertyTabel.register(UINib(nibName: "PropertyCell", bundle: nil), forCellReuseIdentifier: "Cell")
propertyTabel.dataSource = self
propertyTabel.delegate = self
}
didSelectRowAt Function didSelectRowAt函数
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "PropertyDetailsVC") as? PropertyDetailsVC
var dict = arrRes[indexPath.row]
prop.userId = nullToNil(value: dict["user_id"]) as? String
prop.id = nullToNil(value: dict["property_id"]) as? String
prop.code = nullToNil(value: dict["property_code"]) as? String
present(vc!, animated: true, completion: nil)
}
Error Screenshot 错误截图
Add this code in your didSelect
method 将此代码添加到您的didSelect
方法中
let yourStoryboardObject = UIStoryboard(name: "yourStoryboardName", bundle: nil)
let vc = yourStoryboardObject?.instantiateViewController(withIdentifier: "PropertyDetailsVC") as? PropertyDetailsVC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.