开发者

async images problem with threaded data

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开发者_C百科). 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.....


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜