简体   繁体   中英

Scroll to top of WKInterfaceTable in WatchKit?

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?

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 :)

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 :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM