Scroll to particular row in tableView iOS swift

 Problem:

I want to create a table view after fetch data from server want to update the tableview then scroll to particular row 


Solution:

Use the below code to achieve that scroll..

                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {

                        if self.myTV.hasRow(at: IndexPath(arrayLiteral: indexofsection)) {

                            self. myTV.scrollToRow(at: IndexPath(row: 0, sectionindexofsection), at: .top, animated: true)

                        }

                }



Use the extension


extension UITableView {

    

    func hasRow(at indexPath: IndexPath) -> Bool {

        return indexPath.section < self.numberOfSections

    }

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift