这里我使用委托将表格视图单元格中的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)
}
答案 0 :(得分:2)
您需要将cell.boolDelegate
中的tableView(_:cellForRowAt:)
设置为self
中的CheckoutViewController
cell.boolDelegate = self
答案 1 :(得分:2)
您需要在CheckoutViewController
方法
cellForRowAtIndexPath
中设置委托类
cell. boolDelegate = self