我有一个包含单元格的tableview,每个单元格都包含一个“Concept”CoreData Object。它们都有一个名为html的属性,它不是nil(我通过在这个tableview viewDidLoad()
中打印来检查它。问题是,当我尝试在prepareForSegue
中传递时,这种数据会消失。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let indexPath = tableView.indexPathForSelectedRow
if segue.identifier == "toConcept"{
let nc = segue.destination as! UINavigationController
let vc = nc.viewControllers.first as! PDFViewController
print(concepts[(indexPath?.row)!].html
//This prints nothing.
vc.html = concepts[(indexPath?.row)!].html
}
}
问题在于viewDidLoad()
html很好而且没什么,但是在prepareForSegue中没有打印任何内容,而在PDFViewController
它也消失了。
有人知道如何解决这个问题吗?
答案 0 :(得分:0)
试试这个..
func tableView(_ messagesListTableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "toConcept", sender: indexPath)
print(indexPath)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toConcept"{
let indexPath = sender as? IndexPath
let nc = segue.destination as! UINavigationController
let vc = nc.viewControllers.first as! PDFViewController
print(concepts[(indexPath?.row)!].html
//This prints nothing.
vc.html = concepts[(indexPath?.row)!].html
}
}