How to prevent xib cell covering static cell

31 Views Asked by At

So I created a xib cell, and successfully implemented it into my tableVC. I also created a static cell in another section of the tableVC, but when I run the app, the xib cell covers the static cell and only shows the static cell when I click on the xib cell. I read like 10 other questions about this repeating but they were all completely different situations and some were in Objective C, so I tried to copy different answers but none worked.

Here is the tableVC when it loads ....

enter image description here

The button repeats twice, and when I click it, the cell appears with grey over it.

cell

And when i click the xib cell itself, the cell turns white, like how i wanted it to be originally when the vc loaded.

delete cell

I will add my viewDidLoad() , cellForRowAt(), heightForRowAt() methods. There's two sections with one cell in each section as well. Also , the 320 cell height is the exact height of the xib cell.

override func viewDidLoad() {
    super.viewDidLoad()
    
   
    tableView.separatorStyle = .none
   
    
    tableView.register(UINib.init(nibName: Constants.CellDetails.DeleteAccountCell, bundle: nil), forCellReuseIdentifier: Constants.CellDetails.DeleteAccountCellIdentifier)
    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "deleteCell")
    view.backgroundColor = .lightGray
    title = "Delete My Account"
    navigationItem.hidesBackButton = true
    navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "arrow.backward"), style: .done, target: self, action: #selector(backTapped))
    navigationItem.leftBarButtonItem?.tintColor = .white
    navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont(name: Constants.AppFonts.menuTitleFont, size: 35)]
   
}

The cellForRowAt() ...

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: Constants.CellDetails.DeleteAccountCellIdentifier, for: indexPath) as! DeleteAccountCell
    let deleteCell = tableView.dequeueReusableCell(withIdentifier: "deleteCell")
    
 
    
    if indexPath.section == 0 && indexPath.row == 0 {
        return cell
    } else {
        deleteCell?.backgroundColor = .white
        deleteCell?.textLabel?.text = "Delete My Account"
        deleteCell?.textLabel?.textAlignment = .center
        return deleteCell!
    }

   
}

And lastly the heightForRowAt() method.

 override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    
    
    if indexPath.row == 0 && indexPath.section == 0{
        return 320
    } else {
        return 50
    }
   
}

If anyone can point out mistakes and suggestions that would be much appreciated.

0

There are 0 best solutions below