Passing yourself as context in presentControllerWithNames in WatchKit

In my Interface Controller view, I have the following code:

- (IBAction)showModal {
    NSArray *namesArray = @[@"A", @"B", @"C"];
    NSArray *contextsArray = @[self, self, self];
    [self presentControllerWithNames:namesArray contexts:contextsArray];
}

What I would like to do is set the passed context as a delegate property on every page of my modal managed interface controller:

#import "ModalPageInterfaceController.h"

@interface ModalPageInterfaceController ()

@property (nonatomic, weak) id delegate;

@end

@implementation ModalPageInterfaceController

- (instancetype)initWithContext:(id)context {
    self = [super initWithContext:context];
    if (self) {
        self.delegate = context;
    }
    return self;
}

@end

But I found that the context argument is zero for all but the first page when called initWithContext:, so I cannot set the delegation property for these pages. Am I doing something wrong, or is it just a WatchKit error?

+4
source share
3 answers

I understand that this was asked some time ago, but it's worth publishing the solution.

, WatchKit Beta 3 .

, , - .

[self presentControllerWithNames:@[@"First", @"Second", @"Third"],
    contexts:@[@[self], @[@0, self], @[@0, @1, self]]];

, , . , , , NSNumber.

Apple , , Beta 4.

+1

. , ? :

@property (nonatomic, strong) id delegate;
0

Swift: awakeWithContext

:

self.presentControllerWithName("name", context: self)

:

var delegate:AnyObject? = nil
    override func awakeWithContext(context: AnyObject?) {
        self.delegate = context
    }
0
source

All Articles