gpt4 book ai didi

ios - 为什么我的代码执行双重转场?

转载 作者:行者123 更新时间:2023-11-30 14:05:27 24 4
gpt4 key购买 nike

我在 View Controller 上有一个 subMenuViewController,它通过两个不同的 Segue 进行链接,称为 DBSubLegislationSegue 和 TrafficSegue。

当用户从动态表中选择一个单元格时,代码应该检查选择了哪一行,并根据单元格对新的 viewController 执行正确的转场。

当我运行代码时,应用程序总是最终出现在正确的 View Controller 上,但是它通过执行两个 Segue 来实现这一点,第一个 Segue 始终是 Traffic Segue。

任何人都可以帮助确定为什么执行这种双重转场吗?

//populates the table with instances of SubMenuViewCell for each instance filling its label with the correct menuItems
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell =
self.tableView.dequeueReusableCellWithIdentifier(
"SubMenuCell", forIndexPath: indexPath)
as! SubMenuTableViewCell

let row = indexPath.row
cell.subMenuLabel.font =
UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
cell.subMenuLabel.text = subMenuItems[row]
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator //adds disclosure arrow indicating further info to cell

return cell
}

//function for handling when a table row is selected by the user.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//get the selected row index and save as rowSelected
let myIndexPath = self.tableView.indexPathForSelectedRow()
rowSelected = myIndexPath!.row
println(rowSelected)
if(rowSelected == 0){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 1){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 2){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 3){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 4){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 5){
performSegueWithIdentifier("TrafficSegue", sender: nil)
}
if(rowSelected == 6){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 7){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 8){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 9){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 10){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}
if(rowSelected == 11){
performSegueWithIdentifier("DBSubLegislationSegue", sender: nil)
}

}

// MARK: - Navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
println(segue.identifier)
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 0 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "All Entries"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 1 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Common Law"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 2 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Police Procedure"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 3 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Police Powers"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 4 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Crime"
}
if segue.identifier == "TrafficSegue" && rowSelected == 5 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! TrafficSubMenuTableViewController
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 6 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "People"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 7 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Civil Order"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 8 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Sexual"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 9 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Licencing"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 10 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Firearms"
}
if segue.identifier == "DBSubLegislationSegue" && rowSelected == 11 { //check the row and act appropriately
let newViewController = segue.destinationViewController //set the new viewController(new page)
as! LegislationDBQueryTableViewController
newViewController.typeOfPage = "Terrorism"
}

}

最佳答案

全部已修复。

我的错误是在第一个segue中我将动态CELL连接到下一个 View Controller ,但是我的第二个segue是从 TableView 本身连接到 View Controller 。

通过确保两者都从 TableView 本身连接,代码可以按预期工作。

关于ios - 为什么我的代码执行双重转场?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32485560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com