Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use a switch cell for airplane mode and listen to changes.

  • Loading branch information...
commit 876ac2ca3c4293a381777046520b247706ce57a6 1 parent f1b0b44
Jeff Verkoeyen authored
Showing with 26 additions and 1 deletion.
  1. +26 −1 Settings/RootController.m
27 Settings/RootController.m
View
@@ -12,6 +12,10 @@ @interface RootController ()
@property (nonatomic, readwrite, retain) NITableViewModel* model;
@end
+typedef enum {
+ AirplaneModeSwitch,
+} FormIds;
+
@implementation RootController
@synthesize model;
@@ -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.
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.