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 Sep 12, 2012, 11:22 AM   #1
veliborsantic74
macrumors newbie
 
Join Date: Sep 2012
Refreshing images in UITableView

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 is offline   0 Reply With Quote
Old Sep 12, 2012, 08:49 PM   #2
MattInOz
macrumors 68030
 
MattInOz's Avatar
 
Join Date: Jan 2006
Location: Sydney
You might want to have a look at Apple sample code project. Pretty sure there is WWDC video that goes with it.

LazyTableImages
__________________
There is no such thing as "Collective Wisdom"
[ iPhone 5s, iPad Mini, 13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13"]
MattInOz is offline   0 Reply With Quote
Old Sep 13, 2012, 05:31 AM   #3
veliborsantic74
Thread Starter
macrumors newbie
 
Join Date: Sep 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.

Last edited by veliborsantic74; Sep 13, 2012 at 06:39 AM.
veliborsantic74 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:46 PM.

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

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