-1

I try to hide or start the indexPath.row at 1. how can i achieved that ?. I already reversed the indexPath and make the count on numberOfRowsInSection - 1, So the list start from the buttom, but when i clicked on the list the content still not changed according to the reversed indexPath.row

Here is my code

extension PaymentMethodViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return paymentMethod.count
}

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let data = paymentMethod[indexPath.row]
    switch indexPath {
    case indexPathForSelected:
        guard let cell = tableView.dequeueReusableCell(withIdentifier: ConstantsIdentifier.paymentMethodCellId,
                                                       for: indexPath) as? PaymentMethodCell else {
                                                        return UITableViewCell()
                                                        
        }
        cell.layoutIfNeeded()
        cell.setNeedsLayout()
        cell.paymentLbl.text = data.paymentGroupTitle
        cell.subLbl.text = selectedPayment.title
        cell.descriptionLabel.text = selectedPayment.description
        cell.phoneNumberTextField.addTarget(self, action: #selector(textFieldDidChange(sender:)), for: .editingChanged)
        cell.phoneNumberTextField.isHidden = selectedPayment.title == ConstantsText.titleOVO ? false : true
        cell.phoneNumberTextField.textContentType = .telephoneNumber
        cell.phoneNumberTextField.keyboardType = .phonePad
        cell.phoneNumberTextField.delegate = self
        selectedPayment.code == ConstantsPaymentMethod.defaultPaymentCode ? cell.withSeparator() : cell.removeSeparator()
        cell.rightIcon.image = selectedPayment.code == ConstantsPaymentMethod.defaultPaymentCode ? UIImage(named: ConstantsImage.ovalTick) : UIImage(named: ConstantsImage.arrowRight)
        cell.rightIcon.contentMode = .scaleAspectFit
        
        if selectedPayment.code == ConstantsPaymentMethod.defaultPaymentCode {
            hideCellDesc(cell, true)
        } else {
            hideCellDesc(cell, false)
        }
        
        let imageUrl = URL(string: selectedPayment.logo?.lowres ?? "")
        if let objectPayment = paramCheckout?["payment"] as? NSDictionary, let ccNumber = objectPayment["cardNumber"] as? String, !ccNumber.isEmpty {
            cell.paymentImg.image = UIImage(named: getImageCC(ccName: getTypeCreditCard(ccNumber: ccInfo?.ccNumber ?? "")))
        } else {
            cell.paymentImg?.sd_setImage(with: imageUrl, placeholderImage: UIImage(named: ConstantsImage.placeholder), options: .highPriority, completed: nil)
        }
        return cell
        
    default:
        let cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: ConstantsIdentifier.defaultIndentifier, for: indexPath)
        cell.textLabel?.text = data.paymentGroupTitle
        cell.textLabel?.numberOfLines = 2
        cell.textLabel?.font  = UIFont.karlaRegular
        let image = UIImageView(image: UIImage(named: ConstantsImage.arrowRight))
        cell.accessoryView = image
        cell.selectionStyle = .none
        return cell
    }
    
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPathForSelected == indexPath && selectedPayment.title == ConstantsText.titleOVO {
        return Constant.SelectedHeight + 30
    }
    if indexPathForSelected == indexPath && selectedPayment.code == ConstantsPaymentMethod.creditCard {
        return Constant.CellHeight
    }
    return indexPathForSelected == indexPath ? Constant.SelectedHeight + 30 : Constant.CellHeight
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return Constant.HeaderHeight
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return ConstantsText.titlePaymentMethod
}


func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    view.tintColor = UIColor.white
    let header = view as! UITableViewHeaderFooterView
    header.textLabel?.font = UIFont.karlaBold
    header.textLabel?.textColor = UIColor.mainBlue
}

}

Please help me, Thanks

1 Answers1

0

Firstly add UITableViewDelegate, I think this is the problem:

extension PaymentMethodViewController: UITableViewDataSource, UITableViewDelegate {}

and

 override func viewDidLoad() {
     super.viewDidLoad()
     tableView.dataSource = self
     tableView.delegate = self
 }
stoikokolev
  • 484
  • 5
  • 9
  • The Delegate Is in another extension. So it is hide or starting indexPath at 1 is in UITableViewDelegate ? – Rostadhi Mar 21 '22 at 19:45