我是iOS开发的新手,有一个愚蠢的问题,我有一个解析RSS feed的项目,并且一切正常,但是我尝试在后台获取图像以改善UI并坚持如何在TableView单元格中更新UIImageView ?这里的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.titleLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey:@"title"];
NSString* test = [[feeds objectAtIndex:indexPath.row] objectForKey:@"url"];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(doNow:)
object:test];
[queue addOperation:operation];
cell.myImages = theImagePropery;
return cell;
}
-(void)doNow:(NSString*)myData
{
NSString* url = myData;
url = [url stringByReplacingOccurrencesOfString:@" " withString:@""];
NSURL* imageURL = [NSURL URLWithString:url];
NSData* imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage* image = [[UIImage alloc]initWithData:imageData];
[self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO];
}
现在在displayImage方法中,我不知道该怎么办,这就是我的最后一次尝试:
-(void)displayImage:(UIImage *)myImage{
[[self tableView] beginUpdates];
theImageProbery = [[UIImageView alloc] initWithImage:myImage];
[[self tableView] endUpdates];
我能做些什么?
看一下LazyTableImages示例。
它已经过时了,您可以用NSURLSesssionDataTask替换IconDownloader类,但是它将为您提供有关如何构建代码的基本思想。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句