我正试图将值传递给下一个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。
但是,SeGuestDestInVIEW控制器是不存在的。只有SeGu.目标存在。
控制器视图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.
}
*/

}

}
控制器视图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:

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
           }
    }

关于ios - Xcode segue有时在Tableview中工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39386793/

10-12 00:15