CAN CAN - 1 year ago 180
iOS Question

Reload tableView section without reloading header section - Swift

I'm trying to reload tableView section instead of reloading the whole tableview because I have a textfield in the header section and when I call

my keyboard get closed.

I've tried the code below but I get this error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 5 from section 2 which only contains 4 rows before the update'
So please where would be my issue?

let newCount = self.placeArray.count

var newIndexPaths = NSMutableArray(capacity: newCount)

for var i = 0 ; i < newCount ; i++ {
var indexPath = NSIndexPath(forRow: i, inSection: 2)

self.tableView.reloadRowsAtIndexPaths(newIndexPaths as [AnyObject], withRowAnimation: UITableViewRowAnimation.None)

Answer Source

You could use UITableView's reloadSections method instead.

tableView.reloadSections(NSIndexSet(index: 2), withRowAnimation: .None)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download