如何使用单选按钮隐藏表格视图中的部分? [英] How to hide sections in a table view using a radio button?

查看:31
本文介绍了如何使用单选按钮隐藏表格视图中的部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我在表格视图中有四个部分,但在第一部分中所有单元格都有单选按钮.每当它处于活动状态时,我需要显示剩余的三个部分,如果不是,我需要隐藏剩余的最后三个部分,谁能帮我实现这一点?

Here i am having four sections in a table view but in the first section all the cells are having radio buttons. Whenever it is active, I need to show remaining three sections, if not I need to hide the remaining last three sections can anyone help me how to implement this ?

图片如下图 ?

 @IBAction func selectRadioButton(_ sender: KGRadioButton) {
        let chekIndex = self.checkIsRadioSelect.index(of: sender.tag)
        if sender.isSelected {

        } else{
            if(chekIndex == nil){
                self.checkIsRadioSelect.removeAll(keepingCapacity: false)
                self.checkIsRadioSelect.append(sender.tag)
                self.ProductTableView.reloadData()
            }
        } 
    }

    func numberOfSections(in tableView: UITableView) -> Int{
     return 4
    }
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        if (section == 0){
            return "PAYMENT INFORMATION"
        }
        else if (section == 1){
            return "ORDER REVIEW"
        }
        else if (section == 2){
            return "PRODUCT"
        }
        else{
            return ""
        }
    }
    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int){
        let header = view as! UITableViewHeaderFooterView
        header.textLabel?.textColor = UIColor.gray
        header.textLabel?.textAlignment = NSTextAlignment.center
        header.textLabel?.font = UIFont(name: "Futura", size: 17)
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if (section == 0){
            return paymentmethodsArray.count
        }
        else if (section == 2) {
            return productsDetails.count
        }
        else{
            return 1
        }
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
        if (indexPath.section == 0){
            return 44
        }
        else if (indexPath.section == 1){
            return 410
        }
        else if (indexPath.section == 2){
            return 120
        }
        else{
            return 230
        }
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if (indexPath.section == 0){
            let paymentcell = tableView.dequeueReusableCell(withIdentifier: "paymentcell",for:indexPath) as! paymentTableViewCell
            myActivityIndicator.stopAnimating()
            let arr = self.paymentmethodsArray[indexPath.row]
            paymentcell.paymentNameLabel.text = arr["name"]as? String
            paymentcell.radioButton.tag = indexPath.row
            let checkIndex = self.checkIsRadioSelect.index(of: indexPath.row)
            if(checkIndex != nil){
                paymentcell.radioButton.isSelected = true
            }else{
                paymentcell.radioButton.isSelected = false
            }
            return paymentcell
        }
        else if (indexPath.section == 1){
            let shippingAddresscell = tableView.dequeueReusableCell(withIdentifier: "shippingaddresscell",for:indexPath) as! ShippingAddressTableViewCell
            shippingAddresscell.nameLabel.text = name
            shippingAddresscell.addressLabel.text = billingaddress
            shippingAddresscell.mobileNumberLabel.text = String(describing: phoneNumber)
            shippingAddresscell.shippingNameLabel.text = name
            shippingAddresscell.shippingAddressLabel.text = billingaddress
            shippingAddresscell.shippingMobileNumberLabel.text = String(describing: phoneNumber)
            shippingAddresscell.shippingMethodNameLabel.text = shippingMethod
            shippingAddresscell.paymentMethodNameLabel.text = paymentMethod
            return shippingAddresscell
        }
        else if (indexPath.section == 2){
            let productNamecell = tableView.dequeueReusableCell(withIdentifier: "productNamecell",for:indexPath) as! ProductNameTableViewCell
            let arr = productsDetails[indexPath.row]
            let array = arr["product name"] as! String
            productNamecell.productNameLabel.text = array
            productNamecell.priceLabel.text = arr["Price"] as! String
            productNamecell.QuantityLabel.text = String(describing: arr["Quantity"] as! Int)
            productNamecell.subTotalLabel.text = arr["SubTotal"] as! String
            return productNamecell
        }
        else{
            let ordercell = tableView.dequeueReusableCell(withIdentifier: "ordercell",for:indexPath) as! orderTableViewCell
            ordercell.subTotalLabel.text = subTotal
            ordercell.shippingLabel.text = shippingHandling
            ordercell.grandTotalLabel.text = total
            return ordercell
        }
    }

推荐答案

取一个标志(Bool 我的意思是),它的初始值将是 false.现在在单选按钮的选择上将其值设置为 true.

Take one flag (Bool I mean), It's initial value will be false. now on radio button's selection set it's value to true.

现在,更改 numberofSection 方法.它将有条件地返回 14.我的意思是如果你的标志是 true 然后返回 4 否则 1!就这样!

Now, change numberofSection method. It will conditionally returns 1 or 4. I mean if your flag was true then return 4 else 1! that's it!

这篇关于如何使用单选按钮隐藏表格视图中的部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆