Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3 scrollToRowAtIndexPath became scrollToRow

Tags:

swift3

I am converting a Swift 2.3 project o Swift 3 and digging through literally thousands of changes

I currently have code like this:

outletCatalog.scrollToRowAtIndexPath(myIndex, atScrollPoisition: .top, animated: false)

However, it is apparently replaced by

func scrollToRow(at: IndexPath, at: UITableViewScrollPosition, animated: Bool)

However - I don't understand the double parameter naming of "at" and my Google searches did not yield anything. And code translation tools just shows it has

scrollToRow(at:at:animated)
like image 212
Tom Avatar asked Mar 06 '17 21:03

Tom


1 Answers

After code conversion from Swift 2.3 to Swift 3.2 version, you need to call below code inside GCD main dispatch block with the new changes for auto scroll row to index.

DispatchQueue.main.async {
   let index = IndexPath(row: 10, section: 0) // use your index number or Indexpath
   self.tableCart.scrollToRow(at: index,at: .middle, animated: true) //here .middle is the scroll position can change it as per your need
}     

I hope it will work for you.


Support - Swift 3.1, 3.2, 4.1

like image 176
Anand Nimje Avatar answered Sep 21 '22 10:09

Anand Nimje