Created
April 21, 2015 20:38
-
-
Save jacobvanorder/9bf5ada8a7ce93317170 to your computer and use it in GitHub Desktop.
Solution for WKInterface button doesn't change title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Catch and use the model object*/ | |
@interface PresentedViewController() | |
@property (nonatomic, strong) SGYourActionModelObject *actionBlockObject; | |
@end | |
- (void)awakeWithContext:(id)context { | |
NSAssert([context isKindOfClass:[SGYourActionModelObject class]], @"Expected SGYourActionModelObject") | |
self.actionBlockObject = context; | |
} | |
- (void)someMethodThatYouWantToDoSomething { | |
//Something something something | |
[self popController]; | |
self.actionBlockObject.actionBlock(); //BA BOOM! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set up the model object… */ | |
//… Code | |
- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier { | |
if ([segueIdentifier isEqualToString:@"AwesomeSegue"]) { | |
typeof(self) __weak weakSelf = self; | |
YourActionBlock actionBlock = ^(){ | |
//Do whatever want. Use weakSelf. | |
//In your case, you'd change the title of the button. | |
}; | |
return [[SGYourActionModelObject alloc] initWithActionBlock:actionBlock]; //This gets pass to the presented view controller | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <WatchKit/WatchKit.h> | |
typedef void (^YourActionBlock) (/*You could place an object in here*/); | |
@interface SGYourActionModelObject : NSObject | |
@property (nonatomic, strong, readonly) YourActionBlock actionBlock; | |
- (instancetype)initWithActionBlock:(YourActionBlock)actionBlock; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SGYourActionModelObject.h" | |
@interface SGYourActionModelObject () | |
@property (nonatomic, strong) YourActionBlock actionBlock; | |
@end | |
@implementation SGYourActionModelObject | |
- (instancetype)initWithActionBlock:(YourActionBlock)actionBlock { | |
self = [super init]; | |
if (self) { | |
_yourActionBlock = actionBlock; | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much.