Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload section method in swift 3?

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 ?

like image 401
TechChain Avatar asked Nov 02 '16 09:11

TechChain


2 Answers

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)
like image 151
Mohamed Jaleel Nazir Avatar answered Nov 18 '22 08:11

Mohamed Jaleel Nazir


do like in swift3 for more information see this

expandableTableView.reloadSections(IndexSet(integer: gestureRecognizer.view!.tag), with: .automatic)
like image 36
Jenny Tran Avatar answered Nov 18 '22 08:11

Jenny Tran