Reload section method in swift 3?

TechChain picture TechChain · Nov 2, 2016 · Viewed 54.8k times · Source

I have code written in objective c.I want to convert this code into the swift3 code.

[_expandableTableView reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];

After converting using online tool it gave me below code but it does not work

expandableTableView.reloadSections(IndexSet(index: gestureRecognizer.view!.tag), with: .automatic)

Please tell me how to do it ?

Answer

Mohamed Jaleel Nazir picture Mohamed Jaleel Nazir · Feb 2, 2017

Reload Section in Swift 3.0

i.e Reloading 0th section to 0th Section, Because tableview has default one section that index is 0.

//let myRange: ClosedRange = 0...0

self.tableViewPostComments.reloadSections(IndexSet(integersIn: 0...0), with: UITableViewRowAnimation.top)

For Swift 4

self.tableViewPostComments.reloadSections(IndexSet(integersIn: 0...0), with: UITableView.RowAnimation.top)

For Swift 5

In Swift 5 you can use this short & simple line.

self.tableViewPostComments.reloadSections(IndexSet(integersIn: 0...0), with: .top)