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

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 4.34 KB  |  hits: 17  |  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 *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.        
  3.         NSString *CellIdentifier = @"Cell";
  4.        
  5.     ClearLabelsCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  6.  
  7.        
  8.     if (cell == nil) {
  9.         cell = [[[ClearLabelsCellView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
  10.                 cell.backgroundView = [[[GradientView alloc] init] autorelease];
  11.    
  12.    
  13.         UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
  14.                                               initWithTarget:self action:@selector(handleLongPress:)];
  15.         longPress.minimumPressDuration = 1.0; //seconds
  16.         longPress.delegate = self;
  17.         [self.tableView addGestureRecognizer:longPress];
  18.         [longPress release];
  19.    
  20.    
  21.    
  22.    
  23.     }
  24.    
  25.     [cell.customImageView setImage:[UIImage imageNamed:@"Placeholder.png"]];  
  26.  [tableView setBackgroundView:[[[GradientView alloc] init] autorelease]];
  27.      
  28. NSString *byauthor = [(Tweet*)[tweets objectAtIndex:indexPath.row] author];
  29.     NSString *imageName =[NSString stringWithString:[(Tweet*)[tweets objectAtIndex:indexPath.row] author]];    
  30.   NSString *userImage = [NSString stringWithFormat:@"http://api.twitter.com/1/users/profile_image/%@.json?size=bigger", byauthor];
  31.  
  32.    NSArray *myArray = [userImage componentsSeparatedByString: @"/"];
  33.     NSString *fileName = (NSString*)[myArray lastObject];
  34.     NSString *picName =[NSString stringWithFormat:@"%@:%@", imageName, fileName];
  35.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  36.     NSString *documentsDirectory = [paths objectAtIndex:0];
  37.     NSError *error;
  38.    
  39.     NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"];
  40.     NSString* path = [dataPath stringByAppendingPathComponent:picName];
  41.     UIImage* image = [UIImage imageWithContentsOfFile:path];
  42.     [cell.customImageView setImage:image];
  43.     [cell.textLabel setNumberOfLines:10];
  44.     [cell.textLabel setText:[(Tweet*)[tweets objectAtIndex:indexPath.row] tweet]];
  45.  
  46.     NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
  47.     //Wed Dec 01 17:08:03 +0000 2010
  48.     //NSDate *date = [df dateFromString:[[tweets objectAtIndex: storyIndex] objectForKey: TWITTER_CREATED_AT_JSON_KEY]];
  49.      NSDate *date = [NSDate dateWithTimeIntervalSince1970: [[time objectAtIndex:indexPath.row] doubleValue]];
  50.   [df setDateFormat:@"ss"];
  51.     NSString *dateStr = [df stringFromDate:date];
  52.        
  53.     cell.detailTextLabel.text = [NSString stringWithFormat:@"By @%@ %@ ago", byauthor, dateStr];
  54.     cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
  55.     cell.detailTextLabel.textColor = [UIColor grayColor];
  56.     cell.detailTextLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
  57.     usernamestr.text = [NSString stringWithFormat:@"@%@", byauthor];
  58.    
  59.    
  60.     [PMRoundImage roundImageCorners:cell.imageView withQuantity:7.0];
  61.     [cell.customImageView setImage: image];
  62.     [cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
  63.     //cell.delegate = self;
  64.    
  65.     tweetcont.text = [(Tweet*)[tweets objectAtIndex:indexPath.row] tweet];
  66.     [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
  67.    
  68.  
  69.    
  70.     if (!image) {
  71.    
  72.         UIImage *phoneImage=[UIImage imageWithData:[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:userImage]]];
  73.    
  74.         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  75.         NSString *documentsDirectory = [paths objectAtIndex:0];
  76.        
  77.         NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"];
  78.         NSString* path = [dataPath stringByAppendingPathComponent:picName];
  79.         if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
  80.             [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
  81.         NSData* data = UIImagePNGRepresentation(phoneImage);
  82.         [data writeToFile:path atomically:YES];
  83.    
  84.     [cell.customImageView setImage:image];
  85.        
  86.        
  87.     }                      
  88.     else{
  89.         [cell.customImageView setImage:image];
  90.     }
  91.    
  92.         return cell;     
  93. }