Home > front end >  Table View insetGrouped Bug
Table View insetGrouped Bug

Time:12-14

I have expandable table view cells, everything works, except animation. I have one cell with UISwitch, when I tap on it, other cells appear but with some view movements, same thing when I hide these cells when I tap on UISwitch.

I'm using insetGroup Table View and these movements makes view square instead of round.

I want to keep animation, I tried reloadSections(IndexSet(integer: 0), with: .fade) seems like a solution, but it also reloads my header, but I don't want that.

My cellForRowAt func:

internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "RemindersCell", for: indexPath) as! RemindersCell
    
    cell.switchReminder.isOn = remindersAllowed ? true : false
    cell.switchReminder.addTarget(self, action: #selector(switchTapped(sender:)), for: .touchUpInside)
    
    return cell
}

My numberOfRowsInSection func:

internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return remindersAllowed ? 5 : 1
}

My func for UISwitch:

@objc private func switchTapped(sender: UISwitch) {
    
    if !remindersAllowed {
        // Add
        remindersAllowed = true
    } else {
        // Delete
        remindersAllowed = false
    }

    tableView.beginUpdates()
    tableView.reloadSections(IndexSet(integer: 0), with: .none)
    tableView.endUpdates()
}

Default remindersAllowed is true, when I switch it becomes false and hides cells. I really don't understand what the problem is, any help would be appreciated!

The gif shows this bug when I hide the cells.

Here when I hide cells you can notice

CodePudding user response:

you can use activate cell as a tableviewheader

CodePudding user response:

You can try this code to delete system reload section animation and reload section with fade animation:

tableView.reloadData()
tableView.reloadSections(IndexSet(integer: 0), with: .fade)
  • Related