When I revisited the settings screen on MyAppSales to add a switch it turned my stomach how I would have added it over a year ago versus to the way I’m doing it now.
The Old Way
Consider the following snipped just to get a similar nausea so that you can appreciate what I am going to show you afterwards. That’s from a random switch in cellForRowAtIndexPath.
NSString *CellIdentifier = @"ServerSectionSwitch"; SwitchCell *cell = (SwitchCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier]; if (cell == nil) { cell = [[[SwitchCell alloc] initWithFrame:CGRectZero reuseIdentifier: CellIdentifier] autorelease]; } cell.titleLabel.text = @"Enable on WLAN"; ASiSTAppDelegate *appDelegate = (ASiSTAppDelegate *)[[UIApplication sharedApplication] delegate]; cell.switchCtl.on = appDelegate.serverIsRunning; [cell.switchCtl addTarget:appDelegate action:@selector(startStopServer:) forControlEvents:UIControlEventValueChanged]; return cell; |
So obviously I had created a custom tableview cell, so let’s glance at that as well.