开发者

UITable view,loading images from rss feed

开发者 https://www.devze.com 2023-02-16 02:40 出处:网络
I m reading the xml images from rss feed and parsing it in UITable view. Everything works fine, but it takes time to load the image content in the table view. The screen remains frozen. I\'m using NSX

I m reading the xml images from rss feed and parsing it in UITable view. Everything works fine, but it takes time to load the image content in the table view. The screen remains frozen. I'm using NSXMLParser to parse the image. Could you guys help me out, I'd be really greateful. Below is the code.

- (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 stringByAddingPercen开发者_运维技巧tEscapesUsingEncoding: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"];


Use Lazy Loading to load images....


somewhat dated but should put you in the right direction

http://kosmaczewski.net/2009/03/08/asynchronous-loading-of-images-in-a-uitableview/

0

精彩评论

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

关注公众号