如何将表视图单元类中的bool值传递给swift 3中的表视图类?

时间:2017-09-07 05:21:20

标签: ios uitableview swift3

这里我使用委托将表格视图单元格中的bool值传递给表格视图类但无法传递任何人都可以帮助我如何使用任何其他方法传递或者如果不能正确理解我在传递它时出错了什么并在此返回零值?

这是我的表视图类

的代码
 class CheckoutViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,checkoutDelegate,UIGestureRecognizerDelegate,boolValidationDelegate {
 var radio: Bool?
 func boolvalidation(bool: Bool)
    {
        radio = bool
    }
 @IBAction func continueButtonAction(_ sender: Any) {
        print(radio)
        if radio == false {
            let radiobutton = SCLAlertView()
            _ =  radiobutton.showError("Warning", subTitle: "Please select shipping method", closeButtonTitle: "OK")
        }
        else {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let addtoCartVC = storyboard.instantiateViewController(withIdentifier: "payment") as! PaymentMethodViewController
            self.navigationController?.pushViewController(addtoCartVC, animated: true)
        }
    }
 let cell = tableView.dequeueReusableCell(withIdentifier: "shippingmethodcell", for: indexPath) as! MethodTableViewCell
            cell.delegate = self
            return cell

这是我的表格视图单元格类

protocol boolValidationDelegate{
    func boolvalidation(bool: Bool)
}

class MethodTableViewCell: UITableViewCell,UITableViewDataSource,UITableViewDelegate {
 var radioSelection: Bool?
 var boolDelegate: boolValidationDelegate?
func paymentRadioAction(button : KGRadioButton) {
        _ = button.center
        let centralPoint = button.superview?.convert(button.center, to:self.shippingTableView)
        let indexPath =  self.shippingTableView.indexPathForRow(at: centralPoint!)
        if button.isSelected {

        } else{
            chekIndex = indexPath
            radioSelection = true
            self.shippingTableView.reloadData()
        }
        self.boolDelegate?.boolvalidation(bool: radioSelection!)
        print(radioSelection)
    }

2 个答案:

答案 0 :(得分:2)

您需要将cell.boolDelegate中的tableView(_:cellForRowAt:) 设置为self中的CheckoutViewController

cell.boolDelegate = self

答案 1 :(得分:2)

您需要在CheckoutViewController方法

cellForRowAtIndexPath中设置委托类
cell. boolDelegate = self