ios - Transfer data from WKInterfaceTable to another WKInterfaceController -
i not familiar transferring or passing data between 2 wkinterfacecontroller in apple watch. trying , have variable name , age in secondinterfacecontroller need pass value them wkinterfacetable when user tap row . here code :
- (void)table:(wkinterfacetable *)table didselectrowatindex:(nsinteger)rowindex { nsstring *name; nsstring *age; switch (rowindex) { case 0: name = @"jack"; age = @"22"; break; default: break; } nsdictionary *d = [nsdictionary dictionarywithobject:name forkey:@"kname"]; [self pushcontrollerwithname:@"secondinterfacecontroller" context:d]; } but don't know how can access dictionary secondintefacecontroller , pass _name (wkinterfacelable) .
when push secondinterfacecontroller have awakewithcontext: called on , context parameter dictionary passed. can pull name value out of context dictionary , assign label.
- (void)awakewithcontext:(id)context { nsdictionary *dict = (nsdictionary *)context; [_name settext:dict[@"kname"]]; } you can pass multiple values adding multiple keys , values dictionary.
nsdictionary *d = @{@"kname" : name, @"kage" : age}; [self pushcontrollerwithname:@"secondinterfacecontroller" context:d];
Comments
Post a Comment