Xcode segue有时在Tableview中有效

时间:2016-09-08 09:03:42

标签: ios swift xcode

我试图将值传递给下一个ControllerView,但我收到此错误:

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

错误告诉我使用segue.destinationViewController。 但是,segue.destinationViewController是不存在的。只存在segue.destination。

ControllerView 1:

 class TechniqueListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


var activeRow = 0



let cellContent = ["Stance", "Move Forward", "Move Backward", "Move Right", "Move Left", "Jab", "Cross", "Hook", "Uppercut", "Body Jab", "Body Cross", "Body Hook", "Body Uppercut", "Leg Kick", "Body Kick", "Switching Stances", "Switch Leg Kick", "Switch Body Kick", "Push Kick", "Switch Push Kick", "Front Push Kick", "Switch Front Push Kick", "Spinning Back Kick", "Knee", "Switch Knee", "Elbow", "Tornado Kick"]



public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    //gets # of rows


    return cellContent.count
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
 //defines content of each cell

    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "TechniqueCell")
    cell.textLabel?.text = cellContent[indexPath.row]

    return cell

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


    activeRow = indexPath.row
    performSegue(withIdentifier:  "IndividualTechniqueSe", sender:IndividualTechniqueController.self)     

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "IndividualTechniqueSe"{

        let TechniqueIntent = segue.destination as! IndividualTechniqueController
        TechniqueIntent.activeRow2 = activeRow
}


func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

}

ControllerView 2:

import UIKit

class IndividualTechniqueController: UIViewController {

var activeRow2 = 0

override func viewDidLoad() {
    super.viewDidLoad()


    // Do any additional setup after loading the view.
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

每当我构建应用程序并点击一行时,它只会在10%的时间内转到所需的ControllerView。我做错了什么?

1 个答案:

答案 0 :(得分:1)

ControllerView 1:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


            activeRow = indexPath.row
            self.performSegueWithIdentifier("IndividualTechniqueSe", sender:nil)     

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

           if segue.identifier == "IndividualTechniqueSe"{

            let TechniqueIntent = segue.destinationViewController as! IndividualTechniqueController
            TechniqueIntent.activeRow2 = activeRow
           }
    }