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

时间:2018-03-01 08:53:02

标签: ios swift xib

我正在尝试将数据从我的表(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)
    }

错误屏幕截图

1 个答案:

答案 0 :(得分:2)

didSelect方法

中添加此代码
let yourStoryboardObject = UIStoryboard(name: "yourStoryboardName", bundle: nil)

let vc = yourStoryboardObject?.instantiateViewController(withIdentifier: "PropertyDetailsVC") as? PropertyDetailsVC