Skip to content

Commit

Permalink
Use a switch cell for airplane mode and listen to changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Jun 7, 2012
1 parent f1b0b44 commit 876ac2c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Settings/RootController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ @interface RootController ()
@property (nonatomic, readwrite, retain) NITableViewModel* model;
@end

typedef enum {
AirplaneModeSwitch,
} FormIds;

@implementation RootController

@synthesize model;
Expand All @@ -21,9 +25,14 @@ - (id)initWithStyle:(UITableViewStyle)style {
if (self) {
self.title = @"Settings";

// K, we need to show a switch cell here.
NSMutableArray* contents =
[NSMutableArray arrayWithObjects:
[NITitleCellObject objectWithTitle:@"Airplane Mode" image:[UIImage imageNamed:@"Settings-Air"]],
[NISwitchFormElement switchElementWithID:AirplaneModeSwitch
labelText:@"Airplane Mode"
value:YES
didChangeTarget:self
didChangeSelector:@selector(didChangeAirplaneMode:)],
nil];
// NICellFactory here allows us to take advantage of the pre-built bindings between
// Nimbus cells. This way we don't have to create our own factory until we absolutely need to.
Expand All @@ -42,4 +51,20 @@ - (void)loadView {
self.tableView.dataSource = self.model;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
id object = [self.model objectAtIndexPath:indexPath];
if ([object isKindOfClass:[NIFormElement class]]) {
NIFormElement* formElement = object;
if (AirplaneModeSwitch == formElement.elementID) {
cell.imageView.image = [UIImage imageNamed:@"Settings-Air"];
}
}
}

#pragma mark - Form Elements

- (void)didChangeAirplaneMode:(UISwitch *)element {
NSLog(@"%d", element.on);
}

@end

0 comments on commit 876ac2c

Please sign in to comment.