Skip to content

Instantly share code, notes, and snippets.

@bmulholland
Created October 23, 2012 19:34
Show Gist options
  • Save bmulholland/3941052 to your computer and use it in GitHub Desktop.
Save bmulholland/3941052 to your computer and use it in GitHub Desktop.
// NOTE: This is all inherited code and I'd like to change as little as possible right now
// Parent class info
@interface OptionViewController : UITableViewController
// This is called when the right bar button is touched
- (void)nextStep
{
OptionPage* nextStep = [self nextOptionPage];
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[Order currentOrder].needsSave = YES;
UIViewController* nextController = [[appDelegate newOptionViewControllerForPage:nextStep] initWithOptionPages:self.optionPages onStep:(self.step + 1) withCustoms:self.customs forProduct:self.product forEdit:self.editing];
[self.navigationController pushViewController:nextController animated:YES];
}
// This class
@interface MeasurementOptionViewController : OptionViewController <UITextFieldDelegate>
//init
- (id)initWithOptionPages:(NSArray*)pages onStep:(int)step withCustoms:customs forProduct:product forEdit:(BOOL)editing {
if (self = [super initWithOptionPages:pages onStep:step withCustoms:customs forProduct:product forEdit:editing]) {
// Disable scrolling, since these screens have one entry and scrolling introduces a bug
self.tableView.scrollEnabled = NO;
self.title = self.page.title;
OptionChoice* choice = [self currentPageOptionChoice];
self.isCompleted = (choice.choiceMade != nil) && [choice.choiceMade doubleValue] > 0;
static NSString *CellIdentifier = @"Cell";
self.cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (self.cell == nil) {
self.cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
self.cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
CGRect fieldFrame = CGRectMake(0, 0, self.cell.frame.size.width - 20, 44);
self.field = [[UITextField alloc] initWithFrame:fieldFrame];
self.field.backgroundColor = [UIColor colorWithHue:0 saturation:1 brightness:0.3 alpha:0.03];
self.field.font = [UIFont boldSystemFontOfSize:36];
self.field.textAlignment = UITextAlignmentCenter;
self.field.keyboardType = UIKeyboardTypeNumberPad;
[self.field becomeFirstResponder];
[self.field setDelegate:self]; // For formatting
[self.field addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
self.cell.accessoryView = self.field;
self.field.text = [self currentPageOptionChoice].choiceMade;
}
return self;
}
// ....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment