rss 피드에서 xml 이미지를 읽고 UITable보기로 파싱합니다. 모든 것이 잘 작동하지만 테이블 뷰에서 이미지 내용을로드하는 데 시간이 걸립니다. 화면이 계속 고정됩니다. 이미지를 파싱하려면 NSXMLParser
을 사용하고 있습니다. 너희들이 나를 도와 줄 수 있니, 나는 정말로 greate하게 될 것이다. 아래는 코드입니다. 이미지를로드 할UITable보기, rss 피드에서 이미지로드
- (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"];
@mehta을 넣어해야 내가 감사 친구 ...하지만 DIS 물건을 조금 복잡해 보이는 ima noob .... nsxmlparser를 사용하여 다른 방법으로 다른 것들을 빠르게 처리 할 수 있습니까? – kingston
코드는 이미지를 다운로드해도 괜찮습니다 .... 같은 코드를 사용하여 백그라운드 스레드에서 특정 이미지를 다운로드하면됩니다. 너의 테이블이 스크롤되도록 부드럽게 ... 미안하지만 당신은 약간의 시간을 주어야합니다 ... 또 다른 것은 당신이 didStartElement에 할당하고있는 메모리를 해제해야합니다. 그러나 관련이 없습니다. –
위 코드의 어느 부분에서 나를 도울 수 있습니까? .. 정확하게 스레드를 사용해야합니다. – kingston