Search code examples
iosswiftwatchkitwkinterfacetable

WatchKit-Distinguish among tables in table(table, didSelectRowAtIndex)


I have 2 tables in my WKInterfaceController. Clicking on their rows will push to different WKInterfaceController. I need to use override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) because I need to pass a context object.

How do I tell which WKInterfaceTable row is clicked?

Something like this:

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    // If condition A is satisfied
    {
        presentControllerWithName("WKControllerA", context: self)
    }
    else
    {
        presentControllerWithName("WKControllerB", context: self)
    }
}

Solution

  • just check the table and rowIndex like this:

    override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int){
    
        if table==myTable1 && rowIndex==myIndex {
    
                //do something
    
        } else if table==myTable2  && rowIndex==myIndex2  {
    
                //do something else
    
        }
    }