Advertisement
Guest User

cellforRowAtIndexPath Valou_apprem stackoverflow

a guest
May 22nd, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (UITableViewCell *)tableView:(UITableView *)mytableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3.     NSString *a = nil, *b = nil, *c = nil, *d = nil, *e = nil;
  4.     NSUInteger idx = 0;
  5.    
  6.     for ( NSString *string in self.ArrayofFriendsID )
  7.     {
  8.         switch ( idx++ ) {
  9.             case 0: a = string; break;
  10.             case 1: b = string; break;
  11.             case 2: c = string; break;
  12.             case 3: d = string; break;
  13.             case 4: e = string; break;
  14.         }
  15.     }
  16.    
  17. UITableViewCell *cell = [mytableView dequeueReusableCellWithIdentifier:@"thisCell" forIndexPath:indexPath];
  18.    
  19.  
  20. // WHAT COMES IS BAD AND NOT OPTIMAL, NEED TO FIX THAT
  21.     if(indexPath.row == 0)
  22.     {
  23.         NSString *id = a;
  24.         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]];
  25.         NSData *data = [NSData dataWithContentsOfURL:url];
  26.         UIImage *image = [UIImage imageWithData:data];
  27.         cell.imageView.image = image;
  28.     }
  29.     if(indexPath.row == 1)
  30.     {
  31.         NSString *id = b;
  32.         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]];
  33.         NSData *data = [NSData dataWithContentsOfURL:url];
  34.         UIImage *image = [UIImage imageWithData:data];
  35.         cell.imageView.image = image;
  36.     }
  37.     if(indexPath.row ==2)
  38.     {
  39.         NSString *id = c;
  40.         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]];
  41.         NSData *data = [NSData dataWithContentsOfURL:url];
  42.         UIImage *image = [UIImage imageWithData:data];
  43.         cell.imageView.image = image;
  44.     }
  45.     if(indexPath.row == 3)
  46.     {
  47.         NSString *id = d;
  48.         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]];
  49.         NSData *data = [NSData dataWithContentsOfURL:url];
  50.         UIImage *image = [UIImage imageWithData:data];
  51.         cell.imageView.image = image;
  52.     }
  53.     if(indexPath.row == 4)
  54.     {
  55.         NSString *id = e;
  56.         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]];
  57.         NSData *data = [NSData dataWithContentsOfURL:url];
  58.         UIImage *image = [UIImage imageWithData:data];
  59.         cell.imageView.image = image;
  60.     }
  61.    
  62.     cell.frame = CGRectMake(0,0,200,60);
  63.     UIColor * color = [UIColor colorWithRed:230/255.0f green:237/255.0f blue:242/255.0f alpha:1.0f];
  64.     cell.backgroundColor = color;
  65.    
  66.     cell.textLabel.text = [self.ArrayofFiveFriends objectAtIndex:indexPath.row];
  67.     if ([[self.ArrayofFiveFriends objectAtIndex:indexPath.row] isKindOfClass:[NSString class]] &&
  68.         [[self.ArrayofFiveFriends objectAtIndex:indexPath.row] isEqualToString:@""]) {
  69.         cell.textLabel.text = @"";
  70.         cell.contentView.backgroundColor = [UIColor clearColor];
  71.         cell.accessoryType = UITableViewCellAccessoryNone;
  72.     }
  73.     else {
  74.        
  75.         NSDate *object = self.ArrayofFiveFriends[indexPath.row];
  76.         cell.textLabel.text = [object description];
  77.         cell.accessoryType = UITableViewCellAccessoryNone;
  78.     }
  79.  
  80.    
  81.     return cell;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement