to many requests in objective-c, please help

Discussion in 'iOS Programming' started by wfs123, Feb 3, 2013.

  1. macrumors newbie

    Mar 28, 2011
    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:

    - (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");
                NSLog(@"Error: %@",error);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell addSubview:pfimg];
        return cell;
    thank you so much!

  2. macrumors 68030


    Sep 2, 2008
  3. macrumors demi-god


    Oct 16, 2006
    Also checkout NSOperationQueues. They allow you to limit the number of concurrent operations (Downloads).

Share This Page