Swift - 将表视图xib文件中的数据传递给视图控制器

问题描述 投票:0回答:1

我试图将我的表中的数据作为xib文件传递给视图控制器但由于某种原因,代码不起作用并抛出错误。我也浏览过互联网,但没有得到解决方案。

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功能

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)
    }

错误截图

ios swift xib
1个回答
2
投票

didSelect方法中添加此代码

let yourStoryboardObject = UIStoryboard(name: "yourStoryboardName", bundle: nil)

let vc = yourStoryboardObject?.instantiateViewController(withIdentifier: "PropertyDetailsVC") as? PropertyDetailsVC
© www.soinside.com 2019 - 2024. All rights reserved.