Hi there, I'm developing that is grabbing jpegs from parse then placing them inside of a tableview. But whenever I scroll through the table view it lags. I have figured out that this lagging is because I'm sending to many requests.
What I would like to do is send one request when the app launches, download the images then place them in the UITableView. Here is the code where the problem is occurring:
thank you so much!
~Will
What I would like to do is send one request when the app launches, download the images then place them in the UITableView. Here is the code where the problem is occurring:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"cell";
feedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[feedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Add the user's name
cell.userName.text = [object objectForKey:@"name"];
// Add the amount of likes
cell.likes.text = [ NSString stringWithFormat:@"%@", [object objectForKey:@"Likes"]];
PFFile *thumbnail = [object objectForKey:@"imageFile"];
PFImageView *pfimg = [[PFImageView alloc] initWithFrame:CGRectMake(30, 27, 260, 260)];
//
//this is where the problem is happening:
//
[B] [thumbnail getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:data];
pfimg.image = image;
[pfimg loadInBackground];
NSLog(@"No Error");
}else{
NSLog(@"Error: %@",error);
}
}];
[/B]
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addSubview:pfimg];
return cell;
}
thank you so much!
~Will