I've been struggling over the past little while with something that should be dead easy, but I just can't seem to get to work. I'm bolting on a WatchKit interface to an existing iPhone app that I have for sale in the App Store, developed in Objective-C. I simply want to pass an object to the next WKInterfaceController
when I swipe to segue to it.
Given WatchKit doesn't have prepareForSegue, and page-based Relationship Segues don't have identifiers (from what I can tell) which would enable me to use contextForSegueWithIdentifier
, how should I go about passing an object?
I have tried:
_names = [[NSArray alloc]initWithObjects:@"RootInterfaceController",@"StatusInterfaceController",nil];
NSString *passedBAL=@"TEST";
_contextObject=[[NSArray alloc]initWithObjects:passedBAL, nil];
if (firstLoad) {
[WKInterfaceController reloadRootControllersWithNames:_names
contexts:_contextObject];
firstLoad=NO;
in -(void)willActivate
, where I have set a value for the _passedBal
property in -(void)awakeWithContext:(id)context
, and a BOOL to avoid the infinite recursion this method seems to create (very kludgy fix in my view), yet the value is always nil when I arrive at the next WKInterfaceController
. When I set breakpoints and mouse over the variable in the StatusInterfaceController
, it seems to set the value, but as the program continues to execute, it nils it out immediately, though not in response to anything I have written in my code.
Any help would be appreciated, as I have been pulling out my hair on this one, and as I said, it should dead simple.
EDIT:
_passedBAL
was a simple NSString property, but i've changed it in the above to just a straight-up NSString to put in the array for clarity's sake and added my StatusInterfaceController
code. Thanks in advance :)
In my StatusInterfaceController.h , I have the following:
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import "InterfaceController.h"
@interface StatusInterfaceController : WKInterfaceController
@property (strong, nonatomic) NSString *passedBAL;
@end
While in my StatusInterfaceController.m I have:
#import "StatusInterfaceController.h"
@interface StatusInterfaceController ()
@end
@implementation StatusInterfaceController
- (void)awakeWithContext:context {
[super awakeWithContext:context];
_passedBAL=[context objectAtIndex:0];
NSLog(@"Passed BAL is equal to %@",_passedBAL);
// Configure interface objects here.
}