当prepareForSegue调用同一个VC并且VC包含tableView和anthers两个segue动作按钮时,按钮动作segue不起作用

时间:2018-03-27 12:31:14

标签: uitableview swift3 xcode8 ios10 uistoryboardsegue

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

    self.selectedIndexPath = indexPath as NSIndexPath

    performSegue(withIdentifier: "toAddToChart", sender: nil)
}



 open override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    let indexPath = self.selectedIndexPath
    let product = products[indexPath.row]


    if (segue.identifier == "toAddToChart") {
        if  let viewController = segue.destination as? AddToOrderVC  {




        viewController.productName = product.productName
        viewController.productCode = product.productCode
        viewController.productType = product.productType
        viewController.productPrice = product.productPrice
        viewController.productDetails = product.productDescription
        viewController.pImageUrl = product.productimageUrl




    }
}

}

/当我从viweController中删除prepareForSegue函数时它会工作但是当我应用它并且在构建代码后我得到线程1:当按下另一个动作segue按钮时发出SigBArt错误信息

1 个答案:

答案 0 :(得分:0)

何时让产品=产品[indexPath.row] 用确认标识符调出segue的一侧,它将出现错误,因此该错误是

 open override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    let indexPath = self.selectedIndexPath



    if (segue.identifier == "toAddToChart") {
        if  let viewController = segue.destination as? AddToOrderVC  {

        let product = products[indexPath.row]

        viewController.productName = product.productName
        viewController.productCode = product.productCode
        viewController.productType = product.productType
        viewController.productPrice = product.productPrice
        viewController.productDetails = product.productDescription
        viewController.pImageUrl = product.productimageUrl




    }
}

}