Segue正在执行两次 [英] Segue is being executed twice
问题描述
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.selectedClubState = stateNamesForDisplay[indexPath.row]
self.performSegueWithIdentifier ("Cities", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var clubsToPassToCitiesViewController = [clubObject]()
if segue.identifier == "Cities" {
for club in clubsForTable{
if club.clubState == self.selectedClubState{
clubsToPassToCitiesViewController.append(club)
}
}
let citiesView = segue.destinationViewController as? citiesViewController
citiesView?.clubsForChosenCity = clubsToPassToCitiesViewController
}
}
Segue正在执行两次,导致下一个VC。如何防止这种情况发生?
Segue is being executed twice leading to the next VC. How can I prevent this from happening?
推荐答案
你是两次执行segue的人 - 一次自动在故事板中(因为你的segue从单元格原型中发出一个动作Segue),并且当你说 self.performSegueWithIdentifier
时在代码中。如果您不希望segue执行两次,请删除其中一个。
You are the one executing the segue twice — once automatically in the storyboard (because your segue emanates as an Action Segue from the cell prototype), and once in code when you say self.performSegueWithIdentifier
. If you don't want the segue executed twice, remove one of those.
我个人建议您删除 didSelectRow
完全将您的 self.selectedClubState
转移到 prepareForSegue
。
Personally, my recommendation is that you delete didSelectRow
entirely and move your self.selectedClubState
assignment into prepareForSegue
.
这篇关于Segue正在执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!