Skip to content

Instantly share code, notes, and snippets.

@jacobvanorder
Created April 21, 2015 20:38
Show Gist options
  • Select an option

  • Save jacobvanorder/9bf5ada8a7ce93317170 to your computer and use it in GitHub Desktop.

Select an option

Save jacobvanorder/9bf5ada8a7ce93317170 to your computer and use it in GitHub Desktop.
Solution for WKInterface button doesn't change title
/* 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!
}
/* 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
}
#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
#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
@AliAlem
Copy link
Copy Markdown

AliAlem commented Apr 25, 2015

Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment