2

I have a WKInterfaceTable in my storyboard. When a row is tapped, I make changes to the record display but would like to scroll to the top. How do I do this?

This is what my code looks like so far:

@IBOutlet var currentTable: WKInterfaceTable!

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    // Make changes to records...

    // TODO: Scroll to the top???
}

I couldn't find anything in the API for the table currentTable unless there's something I'm missing?

TruMan1
  • 33,665
  • 59
  • 184
  • 335

2 Answers2

3

I wonder how you have overseen this simple solution in the docs?!

This should do the trick:

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) 
{
    // Make changes to records...

    table.scrollToRowAtIndex(0)
}

Also your outlet seems to be wrong. If you create them with IB, it will automatically mark them as 'weak'.

Hope this will help you :)

DevAndArtist
  • 4,971
  • 1
  • 23
  • 48
2

In the docs for WKInterfaceTable, you'll find a helpful method called scrollToRowAtIndex. Simply provide the index for the first row.

https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceTable_class/#//apple_ref/occ/instm/WKInterfaceTable/scrollToRowAtIndex:

bgilham
  • 5,909
  • 1
  • 24
  • 39