【发布时间】:2015-08-21 17:16:15
【问题描述】:
有问题的代码:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
var card: String
if (tableView == self.searchDisplayController?.searchResultsTableView){
card = self.filtered[indexPath.row]
}
else{
card = self.array[indexPath.row]
}
let destinationVC = SearchViewController()
destinationVC.searchString = card
destinationVC.performSegueWithIdentifier("ResultSegue", sender: self)
}
当我的表格中的一个单元格被选中时,我试图将一个字符串传递给另一个视图。在情节提要中,我将 segue 标识符命名为“ResultSegue”。
当我运行我的应用程序时会发生什么,当我单击一个单元格时它会加载下一个视图,而我发送的变量没有更新,然后如果我返回并单击一个新单元格,应用程序将崩溃并给我标题警告。
我尝试过运行 clean,并按照其他线程的建议重置模拟器,但没有任何变化。
【问题讨论】:
-
您的意思是实现 didSelectRow,而不是 didDeselectRow?
-
stackoverflow.com/questions/26207846/pass-data-through-segue 这是一个我认为可以帮助你的问题!向您展示如何传递数据。我也同意@rdelmar,这是错误的功能。
-
@Jay 是的,我将功能修复到了正确的位置。我曾经链接你发布以获得我现在拥有的代码,cmets 中有人遇到了同样的问题,但他们没有具体说明他们是如何解决的