iosswiftuitableviewasyncdisplaykit

Swift - Is it possible to move to the next cell in tableview with the click of a button?


I have a tableview and custom cells which take up the fullscreen however I am wondering if upon click of a button in my cells I could move to the next cell automatically, kind of like how when you scroll more than half in TikTok it automatically goes to the next video. Aside from manually scrolling at a faster speed which is the only way I can think of, is there any other way to automatically move to the next cell, impersonating a full scroll?

Thanks for the help.


Solution

  • You can use that method:

    tableView.scrollToRow(at: indexPath, at: .top, animated: true)

    Approach 1

    Just delegate your tap event (IBAction of the button inside of your custom cell) back to your UIViewController that holds the UITableView reference and call scrollToRow(at:at:animated:).

    Approach 2

    You could also handle with tableView(_:didSelectRowAt:). Next cell would be the indexPath.row + 1 with scrollToRow(at:at:animated:)