Skip to content

Instantly share code, notes, and snippets.

@NilStack
Created June 17, 2015 05:26
Show Gist options
  • Save NilStack/85d9afcf23deb245cf0b to your computer and use it in GitHub Desktop.
Save NilStack/85d9afcf23deb245cf0b to your computer and use it in GitHub Desktop.
code snippet for blog Develop For watchOS 2 2: New UI Elements - Picker
//
// InterfaceController.m
// WatchPicker Extension
//
// Created by Peng on 6/15/15.
// Copyright © 2015 Peng. All rights reserved.
//
#import "InterfaceController.h"
@interface InterfaceController()
@property (weak, nonatomic) IBOutlet WKInterfacePicker *picker;
@property (weak, nonatomic) IBOutlet WKInterfaceLabel *label;
@property (strong, nonatomic) NSArray <WKPickerItem *> *pickerItems;
@property (strong, nonatomic) WKPickerItem *selectedItem;
@end
@implementation InterfaceController
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
WKPickerItem *iOS = [[WKPickerItem alloc] init];
iOS.title = @"iOS";
WKPickerItem *macOSX = [[WKPickerItem alloc] init];
macOSX.title = @"Mac OS X";
WKPickerItem *watchOS = [[WKPickerItem alloc] init];
watchOS.title = @"watchOS";
_pickerItems = @[iOS, macOSX, watchOS];
[_picker setItems:self.pickerItems];
}
- (IBAction)pickerSelected:(NSInteger)value {
WKPickerItem *selectedItem = self.pickerItems[value];
[self.label setText:selectedItem.title];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment