Refreshing images in UITableView

Discussion in 'iOS Programming' started by veliborsantic74, Sep 12, 2012.

  1. veliborsantic74 macrumors newbie

    Sep 6, 2012
    This problem drives me crazy for 9 days. I am downloading some logos from web and set them in TableView. That works OK with iOS 5 built-in method, but the problem is refreshing images. For refreshing I am using PullRefreshTableViewController by Leah Culver (
    I tried also with AFNetworking and SDWebImage but the problem still exists.
    This is part of code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i", indexPath.row];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        NSString *osnovnaAdresaString = @"";
        if (cell == nil)
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    logoKlub1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 40, 75, 16)];
    [cell.contentView addSubview:logoKlub1];
    logoKlubX = [[UIImageView alloc] initWithFrame:CGRectMake(130, 40, 75, 16)];
    [cell.contentView addSubview:logoKlubX];
    logoKlub2 = [[UIImageView alloc] initWithFrame:CGRectMake(210, 40, 75, 16)];
    [cell.contentView addSubview:logoKlub2];
    [self downloadLogoFromAddress:Address1 forClub:logoKlub1]; // Address1 is NSString web address
    [self downloadLogoFromAddress:AddressX forClub:logoKlubX]; // AddressX is NSString web address
    [self downloadLogoFromAddress:Address2 forClub:logoKlub2]; // Address2 is NSString web address
    return cell;
    And method where the logo should sit on its place:
    -(void) downloadLogoFromAddress: (NSString *) webAddress forClub: (UIImageView *) clubLogo
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:webAddress]];
        [NSURLConnection sendAsynchronousRequest:request
                                           queue:[[NSOperationQueue alloc] init]
                                ^(NSURLResponse *response, NSData *data, NSError *error) {
                                   [[NSOperationQueue mainQueue] addOperationWithBlock:
                                        UIImage* pic = [[UIImage alloc]initWithData:data];
                                        [nizLogoKaoSlike addObject:piv]; // tried set logo from NSMutableArray
                                        NSLog(@"Glavni thread? %d", [NSThread isMainThread]); // yes, it is
                                        clubLogo.image = pic;
    							    clubLogo.image = [nizLogoKaoSlike lastObject];
                                        [clubLogo setNeedsLayout];
                                   }];   }]; }
    Instead [clubLogo setNeedsLayout] also tried [clubLogo setNeedsDisplay], but with no luck. After pulling down nizLogoKaoSlike contains refreshed images which number is incremented as I scroll down. I am clueless how to force UIImageViews logoKlub1, logoKlubX and logoKlub2 to refresh. ☹
  2. MattInOz macrumors 68030


    Jan 19, 2006
    You might want to have a look at Apple sample code project. Pretty sure there is WWDC video that goes with it.

  3. veliborsantic74, Sep 13, 2012
    Last edited: Sep 13, 2012

    veliborsantic74 thread starter macrumors newbie

    Sep 6, 2012
    EDIT: Interesting, I have noticed that all three images on UIImageViews in the last cell are changed, not only once, but more times - like on the slot machines.

Share This Page