Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

veliborsantic74

macrumors newbie
Original poster
Sep 6, 2012
9
0
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 (https://github.com/leah/PullToRefresh).
I tried also with AFNetworking and SDWebImage but the problem still exists.
This is part of code:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i", indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSString *osnovnaAdresaString = @"http://www.odds1x2.com/";
    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:
Code:
-(void) downloadLogoFromAddress: (NSString *) webAddress forClub: (UIImageView *) clubLogo
{
    
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:webAddress]];
 
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[[NSOperationQueue alloc] init]
                           completionHandler:
                            ^(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. ☹
 

veliborsantic74

macrumors newbie
Original poster
Sep 6, 2012
9
0
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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.