|
|
#1 |
|
to many requests in objective-c, please help
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: 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:
//
[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);
}
}];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addSubview:pfimg];
return cell;
}
~Will |
|
|
|
0
|
|
|
#2 |
|
Apple Sample Code LazyTableImages.
|
|
|
|
0
|
|
|
#3 |
|
Also checkout NSOperationQueues. They allow you to limit the number of concurrent operations (Downloads).
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 11:00 PM.







Linear Mode
