【发布时间】:2019-01-23 07:56:32
【问题描述】:
I'm currently making a to do list app using Swift 4. The home view controller has a tableview with some categories in it and when one is selected, it takes the user to a view controller where the items in that category are列出。但是我有一个错误,因为列表中只显示了最近的项目。
我认为这是由于我导航到列表视图控制器的方式。我目前正在这样做:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let destinationVC = ListVC()
if let indexPath = tableView.indexPathForSelectedRow {
destinationVC.selectedCategory = categoryArray[indexPath.row]
}
navigationController?.pushViewController(destinationVC, animated: true)
tableView.deselectRow(at: indexPath, animated: true)
}
在列表视图控制器中,我只需要这个来加载数据:
var selectedCategory : Category? {
didSet {
loadItems()
}
}
我首先使用故事板创建了这个应用程序,当使用 segues 时,它工作得非常好。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "goToItems", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! TodoListVC
if let indexPath = tableView.indexPathForSelectedRow {
destinationVC.selectedCategory = categoryArray[indexPath.row]
}
}
所以基本上,问题是在二级列表视图控制器中,即使它们存储在核心数据中,它也只会显示最近添加的项目而不会显示其他项目。我认为这与我每次创建新对象时显示辅助视图控制器的方式有关。
如何正确转到下一个视图控制器?
【问题讨论】:
-
漏洞在
loadItems。