- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*calculate x up here*/
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
x = 320 * 1.7;}
else {
x = 175;
}
/* load a reuseable identifier (with the correct identifier)*/
UITableViewCell *cell = nil;
if (indexPath.section == 0) {
cell = [table dequeueReusableCellWithIdentifier:@"cellTextIdentifier"];
} else {
cell = [table dequeueReusableCellWithIdentifier:@"cellNormalIdentifier"];
}
/* init it if a resusable one couldn't be found */
if( cell == nil)
{
if (indexPath.section == 0 )
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellTextIdentifier"];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, x, 21)]; //init the text field here so we don't have to keep making new text fields (we can reuse this one now)
cell.accessoryView = textField;
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellNormalIdentifier"];
}
}
//create text cell sizes approprate to device (iPad or other iDevices)
//NSLog(currentDevice);
//its not an iPad we need to keep the textFields small!
NSString *string = [NSString stringWithFormat:@"%d", cell.frame.size.width];
NSLog(string);
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (indexPath.section == 0 && indexPath.row == 0) {
//Create Username Cell
cell.textLabel.text = @"Username:";
UITextField *textField = cell.accessoryView; //we get the cell what we created earlier
if (_loggedin)
{
textField.enabled = false;
}
textField.text = [prefs valueForKey:@"username"];
textField.placeholder = @"Enter Username";
textField.delegate = self;
textField.keyboardAppearance = UIReturnKeyDone;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.tag = 1;
textField.clearButtonMode = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else if (indexPath.section == 0 && indexPath.row == 1) {
//Create Password Cell
cell.textLabel.text = @"Password:";
UITextField *textField = cell.accessoryView; //we get the cell what we created earlier
if (_loggedin)
{
textField.enabled = false;
}
textField.placeholder = @"Enter Password";
textField.secureTextEntry = YES;
textField.text = [prefs valueForKey:@"password"];
textField.delegate = self;
textField.keyboardAppearance = UIReturnKeyDone;
textField.tag = 2;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.clearButtonMode = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else if (indexPath.section == 2 && indexPath.row == 0) {
cell.textLabel.text = @"Copy URL To Clipboard";
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
NSString *clippy = [prefs valueForKey:@"clipboard"] ;
if ([clippy isEqualToString:@"1"])
{
[switchView setOn:YES animated:YES];
}
cell.accessoryView = switchView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//[switchView setOn:NO animated:NO];
[switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
}
else if (indexPath.section == 2 && indexPath.row == 1) {
cell.textLabel.text = @"Allow Image Editing";
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
NSString *clippy = [prefs valueForKey:@"editing"] ;
if ([clippy isEqualToString:@"1"])
{
[switchView setOn:YES animated:YES];
}
cell.accessoryView = switchView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//[switchView setOn:NO animated:NO];
[switchView addTarget:self action:@selector(editingChanged:) forControlEvents:UIControlEventValueChanged];
}else if (indexPath.section == 2 && indexPath.row == 2) {
//Create shoutbox
cell.textLabel.text = @"Clear Image Cache";
cell.textAlignment = UITextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
else if (indexPath.section == 1 && indexPath.row == 0)
{
if (!_loggedin)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
cell.textLabel.text = @"Create Account";
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator ;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
cell.textLabel.text = @"View Privacy Policy";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator ;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
} else if (indexPath.section == 1 && indexPath.row == 1 && _loggedin)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] ;
cell.textLabel.text = @"Image Space:";
cell.detailTextLabel.text = @"125/1000";
}
else if (indexPath.section == 1 && indexPath.row == 2 && _loggedin)
{
if (premium)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] ;
cell.textLabel.text = @"Premium Remaining:";
cell.detailTextLabel.text = @"2 Days";
}else{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
cell.textLabel.text = @"Buy Premium Now";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}else if (indexPath.section == 1 && indexPath.row == 3 && _loggedin)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"View Premium Features";
}
return cell;
}