当在同一 VC 中准备ForSegue 调用且 VC 包含表视图和花药时,按钮操作 segue 不起作用



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中删除PreparForsegue函数时,它将起作用,但是当我应用它和构建代码后,我会得到线程1:Signal Sigbart错误,当另一个操作SEGUE按钮按下

当let product = product [indexpath.row]时用确认标识符将SEGUE的侧面称为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


    }
}
}

相关内容

最新更新