UITable视图,从rss feed加载图像
我读取rss提要的XML图像并解析它在UITable视图。一切工作正常,但它需要时间来加载表格视图中的图像内容。屏幕仍然冻结。我正在使用NSXMLParser
解析图像。你们能帮我一把吗,我真的很贪婪。以下是代码。UITable视图,从rss feed加载图像
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
currentElement1=[attributeDict copy];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentString=[[NSMutableString alloc] init];
//currentImage = [[NSMutableString alloc] init];
currentContent=[[NSMutableString alloc]init];
}
if ([attributeDict objectForKey:@"url"])
{
currentString=[attributeDict objectForKey:@"url"];
// NSLog(@"what is my current string:%@",currentString);
[item setObject:currentString forKey:@"url"];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"description"];
[item setObject:currentContent forKey:@"content:encoded"];
[item setObject:currentDate forKey:@"pubDate"];
[stories addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...///////////element
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
}
else if ([currentElement isEqualToString:@"content:encoded"]) {
[currentSummary appendString:string];
}
}
NSString *imagefile1 = [[stories objectAtIndex:indexPath.row]objectForKey:@"url"];
NSString *escapedURL=[imagefile1 stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
UIImage *image1 = [[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:escapedURL]]];
cell.imageView.image=image1;
[image1 release];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.textLabel.numberOfLines=2;
cell.textLabel.text=[[stories objectAtIndex:indexPath.row] objectForKey: @"title"];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];
cell.detailTextLabel.numberOfLines=3;
cell.detailTextLabel.text=[[stories objectAtIndex:indexPath.row] objectForKey: @"pubDate"];
有点过时,但应该把你在正确的方向
http://kosmaczewski.net/2009/03/08/asynchronous-loading-of-images-in-a-uitableview/
下面是可能的wid nsxmlparser ...无论如何谢谢 – kingston 2011-03-10 07:19:11
他是usin g NSXMLParser。见第54行[https://github.com/akosma/async-uitableview/blob/master/Classes/Helpers/RSS.m](https://github.com/akosma/async-uitableview/blob/master/Classes /Helpers/RSS.m) – 2011-03-10 09:25:36
谢谢...我会试一试 – kingston 2011-03-10 09:39:35
@mehta:哥们我欣赏...但DIS东西看起来有点复杂的ima noob ....是否可能使用nsxmlparser以任何其他方式加速dis东西 – kingston 2011-03-10 05:36:31
您的代码可以下载图像....您只需要使用相同的代码在后台线程中下载特定图像。让你的桌子滚动顺利...对不起,但你需要给点时间这...你需要释放内存也是你在didStartElement中分配的内存,但这是不相关的 – 2011-03-10 05:45:57
可以帮助我在上面的代码的哪一部分。 ..我完全可以使用线程 – kingston 2011-03-10 05:53:48