Search code examples
uitableviewswift3xcode8ios10uistoryboardsegue

Button action segue doesn't work when prepareForSegue call in the same VC and VC contains tableView and anthers two segue action button


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




    }
}

}

/when i remove prepareForSegue function from viweController its will work but when i apply it and after build the code i get thread 1:signal SigBArt error when another action segue button pressed


Solution

  • When let product = products[indexPath.row] called out side of the segue with confirm identifier,it will beget an error so the of this error is

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