views:

31

answers:

2

im having an issue with my tableviews and threaded data. in my app im downloading data in xml, including an image url which im then parsing to get the image for my tableviews.

im using the asyncimageview class (markj.net). if i thread the download of my xml, then realoadData the cells appear fine , appart form the images never load, until they are dequeued and reloaded, and i have no idea how to fix it.

help please.....

A: 

ok i managed to fix it using this

- (void)loadImagesForVisibleCells;

{ NSArray cells = [self.newsStories visibleCells]; [cells retain]; for (int i = 0; i < [cells count]; i++) { // Go through each cell in the array and call its loadContent method if it responds to it. CGRect frame; frame.size.width=75; frame.size.height=75; frame.origin.x=0; frame.origin.y=0; AsyncImageView asyncImage = [[[AsyncImageView alloc] initWithFrame:frame] autorelease];

    //AsyncImageView *asyncImage = (AsyncImageView *)[[cells objectAtIndex: i] retain];
     //*flickrCell = (FlickrCell *)[[cells objectAtIndex: i] retain];
    NewcastleStories *aStory = [stories objectAtIndex:i];
    //AsyncImageView* asyncImage = [[AsyncImageView alloc]init];
    [asyncImage emptyImages];

    NSURL* url  =[NSURL URLWithString:aStory.picture];
    [asyncImage loadImageFromURL:url];
    //[cells objectAtIndex:i])
    static NSString *CellIdentifier = @"ImageCell";
    UITableViewCell *cell = [newsStories dequeueReusableCellWithIdentifier:CellIdentifier];

    [cell.contentView addSubview:asyncImage];
    [[self newsStories]setNeedsLayout]; 
    [[self newsStories] setNeedsDisplay]; 
    //[self dataLoaded];
    //[asyncImage loadImage];
    //[flickrCell release];
    //flickrCell = nil;
}
[cells release];

}

but it has to be called in the main thread using

[self performSelectorOnMainThread:@selector(loadImagesForVisibleCells) withObject:nil waitUntilDone:YES];
richard Stephenson