How to Push Data From one WKInterfaceController to Another?

1.1k Views Asked by At

I have 2 Interface Controllers in my WatchKit. The first one is called InterfaceController while the other is called DetailsForWatch. IC has a tableView on it. It parses data from a Parse class, and displays data from each entry in the class as a row. This works fine.

What I am trying to do is pass the PFObject for the selected row to a PFObject in DetailsForWatch. My setup for DFW is:

.h

@interface DetailsForWatch : WKInterfaceController {
}
@property (nonatomic, retain) IBOutlet WKInterfaceLabel *detailsLabel;
@property (nonatomic, retain) PFObject *finalObject;

@end

.m

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    NSString *details = self.finalObject [@"Request"];

    [self.detailsLabel setText:details];
    NSLog(@"%@", self.finalObject);
    // Configure interface objects here.
}

In IC, for .h I have:

@class DetailsForWatch;
@interface InterfaceController : WKInterfaceController {
    DetailsForWatch *_theDetails;


}
@property (retain) DetailsForWatch *theDetails;
@end

In the .m I have:

@synthesize theDetails = _theDetails;

for didSelectRowAtIndex, I have:

_theObject = _theObjective[rowIndex];

    self.theDetails = [[DetailsForWatch alloc] init];
    _theDetails.finalObject = _theObject;

I set up the DFW as a Push selection from the Group on IC. When I select a row in the IC, it pushes a blank screen, and the NSLog shows that the PFObject named finalObject is (null). What am I doing wrong that it is not passing on PFObject properly?

1

There are 1 best solutions below

0
On BEST ANSWER

There are a couple of ways to pass data between the two interface controllers. The way I have been doing it is like this:

  1. create a segue (give it an identifier if necessary) between the two controllers in my storyboard.

  2. In interface controller 1 implement

- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier

it will be called when the segue is triggered via button press or whatever.

This can return any object such as a dictionary of the data (in your case 'theDetails')

  1. In interface controller 2 implement

- (void)awakeWithContext:(id)context

the context object here will be the one you passed through in controller 1