gpt4 book ai didi

ios - 如何使用单选按钮隐藏表格 View 中的部分?

转载 作者:行者123 更新时间:2023-12-01 18:39:52 27 4
gpt4 key购买 nike

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

图片如下图enter image description here ?

 @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 .

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

关于ios - 如何使用单选按钮隐藏表格 View 中的部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44901646/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com