Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 3, 2013, 10:37 PM   #1
wfs123
macrumors newbie
 
Join Date: Mar 2011
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;
}
thank you so much!

~Will
wfs123 is offline   0 Reply With Quote
Old Feb 3, 2013, 11:23 PM   #2
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Apple Sample Code LazyTableImages.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 4, 2013, 06:20 AM   #3
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
Also checkout NSOperationQueues. They allow you to limit the number of concurrent operations (Downloads).
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: iAds - No Requests Sean7512 iPhone/iPad Programming 10 Apr 3, 2014 05:23 AM
Feature Requests roxics iOS 7 9 Sep 19, 2013 10:31 AM
Friend requests smithrh Site and Forum Feedback 2 Jun 5, 2013 03:24 PM
City wallpaper requests. Caris Picture Gallery 11 Jun 4, 2013 06:08 AM
Passing requests through a proxy. lawlessc iPhone/iPad Programming 1 May 11, 2013 06:39 PM

Forum Jump

All times are GMT -5. The time now is 11:30 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC