Reload Tableview Section Without Scroll or Animation

Reload tableview section without scroll or animation

Try this:

UIView.setAnimationsEnabled(false)
self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1) as IndexSet, with: UITableViewRowAnimation.none)
self.tableView.endUpdates()

Tableview with no animation still jitters when I reload section

2 things were needed:

  1. Get a reference/pointer to the headerView. E.g. this answer.

  2. Have your button as a property. I was originally having it just as a subview. That wasn't enough!
    To do such I made my sectionHeader a UITableViewHeaderFooterView subclass and then added the button as a property.

Then I was simply able to change the isEnabled property of the button.

UITableView Refresh without scrolling

I am showing if only one row is being added. You can extend it to multiple rows.

    // dataArray is your data Source object
[dataArray insertObject:name atIndex:0];
CGPoint contentOffset = self.tableView.contentOffset;
contentOffset.y += [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[self.tableView reloadData];
[self.tableView setContentOffset:contentOffset];

But for this to work you need to have defined - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath the method. Or else, you can directly give your tableview row height if it is constant.

Reload tableView section without reloading header section - Swift

You could use UITableView's reloadSections method instead.

tableView.reloadSections(IndexSet(integer: 2), with: .none)

How to reload a section header without it disappearing/re-appearing in Swift?

Found a solution referenced by @Abhinav:

Reload tableview section without scroll or animation

Slight modification updated for Swift 3.0:

UIView.performWithoutAnimation {

self.tableView.beginUpdates()
self.tableView.reloadSections(indexSet, with: UITableViewRowAnimation.none)
self.tableView.endUpdates()

}

Now if I scroll past the number of visible cells on screen and I delete a row, the headerCell.theCountLabel.text in my section header is updated without any animation, and remains still.



Related Topics



Leave a reply



Submit