Skip to content

Instantly share code, notes, and snippets.

@jhollida24
Created March 22, 2013 18:32
Show Gist options
  • Save jhollida24/5223630 to your computer and use it in GitHub Desktop.
Save jhollida24/5223630 to your computer and use it in GitHub Desktop.
#import "RegisterUserController.h"
#import "GlobalConstants.h"
#import "BSRegistrationCell.h"
#import "SyncController.h"
#import "BSButton.h"
#import "NSThread+BlocksAdditions.h"
@interface RegisterUserController ()
@property (nonatomic, retain) SyncController* sync;
@property (nonatomic, retain) IBOutlet UITableView* table;
@property (nonatomic, retain) IBOutlet UIView* footerView;
@property (nonatomic, retain) IBOutlet BSButton* createButton;
@property (nonatomic, assign) BOOL isStudent;
@property (nonatomic, assign) BOOL isTeacher;
@property (nonatomic, retain) NSString* firstName;
@property (nonatomic, retain) NSString* lastName;
@property (nonatomic, retain) NSString* email;
@property (nonatomic, retain) NSString* password;
@property (nonatomic, retain) NSString* confirm;
- (IBAction)registerUser;
@end
@implementation RegisterUserController
#define SELECTION_SECTION 0
#define PARAMS_SECTION 1
#define I_AM_A_STUDENT_ROW 0
#define I_AM_A_TEACHER_ROW 1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == SELECTION_SECTION)
{
UITableViewCell* cell = nil;
static NSString* cellIdentifier = @"SelectionCell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
cell.detailTextLabel.textColor = [UIColor lightGrayColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:17];
}
if (indexPath.row == I_AM_A_STUDENT_ROW)
{
cell.textLabel.text = NSLocalizedString(@"Student", @"");
cell.accessoryType = (self.isStudent ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone);
cell.detailTextLabel.text = self.isStudent ? nil : NSLocalizedString(@"Tap to check", @"");
}
else if (indexPath.row == I_AM_A_TEACHER_ROW)
{
cell.textLabel.text = NSLocalizedString(@"Teacher", @"");
cell.accessoryType = (self.isTeacher ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone);
cell.detailTextLabel.text = self.isTeacher ? nil : NSLocalizedString(@"Tap to check", @"");
}
return cell;
}
else if (indexPath.section == PARAMS_SECTION)
{
BSRegistrationCell* regCell;
static NSString* regCellIdentifier = @"BSRegistrationCell";
regCell = [tableView dequeueReusableCellWithIdentifier:regCellIdentifier];
if (regCell == nil)
{
regCell = [BSRegistrationCell registrationCell];
regCell.selectionStyle = UITableViewCellSelectionStyleNone;
regCell.field.delegate = self;
regCell.tag = indexPath.row;
}
if (indexPath.row == passwordCell || indexPath.row == confirmCell)
{
regCell.field.secureTextEntry = YES;
}
if (indexPath.row == ([self tableView:self.table numberOfRowsInSection:PARAMS_SECTION] - 1))
{
regCell.field.returnKeyType = UIReturnKeyDone;
}
regCell.fieldNameLabel.text = [self labelNameForRow:indexPath.row];
regCell.field.text = [self valueForRow:indexPath.row];
return regCell;
}
NSAssert(NO, @"Should not be here");
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == SELECTION_SECTION)
{
UITableViewCell* cell = [self.table cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.text = nil;
[self.table deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == I_AM_A_STUDENT_ROW)
{
self.isStudent = !self.isStudent;
cell.accessoryType = (self.isStudent ?UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone);
}
else if (indexPath.row == I_AM_A_TEACHER_ROW)
{
self.isTeacher = !self.isTeacher;
cell.accessoryType = (self.isTeacher ?UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone);
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment