Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 5th, 2012  |  syntax: Objective C  |  size: 6.87 KB  |  hits: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3.     /*calculate x up here*/
  4.     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  5.         x = 320 * 1.7;}
  6.     else {
  7.         x = 175;
  8.     }
  9.  
  10.  
  11.     /* load a reuseable identifier (with the correct identifier)*/
  12.     UITableViewCell *cell = nil;
  13.     if (indexPath.section == 0) {
  14.         cell = [table dequeueReusableCellWithIdentifier:@"cellTextIdentifier"];
  15.     } else {
  16.         cell = [table dequeueReusableCellWithIdentifier:@"cellNormalIdentifier"];
  17.     }
  18.  
  19.     /* init it if a resusable one couldn't be found */
  20.     if( cell == nil)
  21.     {
  22.      
  23.         if (indexPath.section == 0 )
  24.         {
  25.             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellTextIdentifier"];  
  26.             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)
  27.             cell.accessoryView = textField;
  28.         }
  29.         else
  30.         {
  31.             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellNormalIdentifier"];  
  32.         }
  33.        
  34.     }
  35.    
  36.         //create text cell sizes approprate to device (iPad or other iDevices)
  37.         //NSLog(currentDevice);
  38.        
  39.        
  40.    
  41.     //its not an iPad we need to keep the textFields small!
  42.     NSString *string = [NSString stringWithFormat:@"%d", cell.frame.size.width];
  43.    NSLog(string);
  44.        
  45.     NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  46.    
  47.         if (indexPath.section == 0 && indexPath.row == 0) {
  48.                 //Create Username Cell
  49.                 cell.textLabel.text = @"Username:";
  50.         UITextField *textField = cell.accessoryView; //we get the cell what we created earlier
  51.         if (_loggedin)
  52.         {
  53.             textField.enabled = false;
  54.         }
  55.                 textField.text = [prefs valueForKey:@"username"];
  56.         textField.placeholder = @"Enter Username";
  57.         textField.delegate = self;
  58.                 textField.keyboardAppearance = UIReturnKeyDone;
  59.         textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
  60.         textField.autocorrectionType = UITextAutocorrectionTypeNo;
  61.                 textField.tag = 1;
  62.                 textField.clearButtonMode = YES;
  63.                 cell.selectionStyle = UITableViewCellSelectionStyleNone;
  64.        
  65.         } else if (indexPath.section == 0 && indexPath.row == 1) {
  66.                 //Create Password Cell
  67.                 cell.textLabel.text = @"Password:";
  68.        
  69.                 UITextField *textField = cell.accessoryView; //we get the cell what we created earlier
  70.         if (_loggedin)
  71.         {
  72.             textField.enabled = false;
  73.         }
  74.         textField.placeholder = @"Enter Password";
  75.                 textField.secureTextEntry = YES;
  76.                 textField.text = [prefs valueForKey:@"password"];
  77.         textField.delegate = self;
  78.                 textField.keyboardAppearance = UIReturnKeyDone;
  79.                 textField.tag = 2;
  80.         textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
  81.         textField.autocorrectionType = UITextAutocorrectionTypeNo;
  82.                 textField.clearButtonMode = YES;
  83.        
  84.                 cell.selectionStyle = UITableViewCellSelectionStyleNone;
  85.         } else if (indexPath.section == 2 && indexPath.row == 0) {
  86.         cell.textLabel.text = @"Copy URL To Clipboard";
  87.         UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
  88.         NSString *clippy = [prefs valueForKey:@"clipboard"] ;
  89.        
  90.         if ([clippy isEqualToString:@"1"])
  91.         {
  92.             [switchView setOn:YES animated:YES];
  93.            
  94.         }
  95.         cell.accessoryView = switchView;
  96.         cell.selectionStyle = UITableViewCellSelectionStyleNone;
  97.         //[switchView setOn:NO animated:NO];
  98.         [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  99.        
  100.         }
  101.     else if (indexPath.section == 2 && indexPath.row == 1) {
  102.         cell.textLabel.text = @"Allow Image Editing";
  103.         UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
  104.         NSString *clippy = [prefs valueForKey:@"editing"] ;
  105.        
  106.         if ([clippy isEqualToString:@"1"])
  107.         {
  108.             [switchView setOn:YES animated:YES];
  109.            
  110.         }
  111.         cell.accessoryView = switchView;
  112.         cell.selectionStyle = UITableViewCellSelectionStyleNone;
  113.         //[switchView setOn:NO animated:NO];
  114.        
  115.         [switchView addTarget:self action:@selector(editingChanged:) forControlEvents:UIControlEventValueChanged];
  116.     }else if (indexPath.section == 2 && indexPath.row == 2) {
  117.                 //Create shoutbox
  118.                 cell.textLabel.text = @"Clear Image Cache";
  119.         cell.textAlignment = UITextAlignmentCenter;
  120.         cell.selectionStyle = UITableViewCellSelectionStyleBlue;
  121.         }  
  122.     else if (indexPath.section == 1 && indexPath.row == 0)
  123.     {
  124.         if (!_loggedin)
  125.         {
  126.             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
  127.             cell.textLabel.text = @"Create Account";
  128.             cell.textLabel.textAlignment = UITextAlignmentCenter;
  129.              cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator ;
  130.             cell.selectionStyle = UITableViewCellSelectionStyleBlue;
  131.         }
  132.         else
  133.         {
  134.             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
  135.             cell.textLabel.text = @"View Privacy Policy";
  136.             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator ;
  137.             cell.selectionStyle = UITableViewCellSelectionStyleBlue;
  138.         }
  139.        
  140.     } else if (indexPath.section == 1 && indexPath.row == 1 && _loggedin)
  141.     {
  142.        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] ;
  143.         cell.textLabel.text = @"Image Space:";
  144.         cell.detailTextLabel.text = @"125/1000";  
  145.        
  146.     }
  147.     else if (indexPath.section == 1 && indexPath.row == 2 && _loggedin)
  148.     {
  149.         if (premium)
  150.         {
  151.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] ;
  152.         cell.textLabel.text = @"Premium Remaining:";
  153.         cell.detailTextLabel.text = @"2 Days";
  154.         }else{
  155.             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
  156.             cell.textLabel.text = @"Buy Premium Now";
  157.             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;  
  158.         }
  159.        
  160.        
  161.     }else if (indexPath.section == 1 && indexPath.row == 3 && _loggedin)
  162.     {
  163.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] ;
  164.         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  165.         cell.textLabel.text = @"View Premium Features";
  166.          
  167.     }
  168.    
  169.  
  170.     return cell;        
  171. }