Search code examples
iosobjective-cwatchkitapple-watchwkinterfacetable

Need to Pass data when user tabs on Table View row to another DetailedInterfaceController in Watchkit


Hello I am new to IOS Watchkit Development.

I need to pass the data when user tabs on the table row. I have tried both ways using segue and using the pushControllerWithName and even tried presentControllerWithName in the method

-(void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex
{
     [self contextForSegueWithIdentifier:@"navigare" inTable:self.tbl rowIndex:rowIndex];
     //And Tried following
     [self pushControllerWithName:(NSString *)@"ProfileInterfaceController" context: rowValue];

}

Any help here ?


Solution

  • Are you having issues accessing the 'rowValue' from ProfileInterfaceController? Or are you just unsure how to accomplish this?

    WatchKit allows you to send data to a WKInterfaceController with a segue using the presentControllerWithName:Context: method.

    Name - is the name assigned to the destination WKInterfaceController in Interface Builder (not the name of the file or any other).
    Context - is an NSDictionary parameter which you use to send data.

    When the destination WKInterfaceController is initialised the awakeWithContext: method is called, and your context dictionary is available for use.

    In the code snippet you've provided it's hard to understand 'rowValue'. This needs to be wrapped up in an NSDictionary object before sending.

    Check out Apple's Framework Reference for more information

    Unrelated, but worth noting - it's unnecessary to prepend (NSString *) when using the NSString literal syntax (@"This is a string") in Objective C.