Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:35:38+00:00 2026-06-13T16:35:38+00:00

I am getting data via RSS feeds and displaying each article in a table

  • 0

I am getting data via RSS feeds and displaying each article in a table view cell. Each cell has an image view, set to a default image. If the page has an image, the image is to be replaced with the image from the article. As of now, each cell downloads the source code from the web page, causing the app to lag when I push the view controller and when I try scrolling.

Here is what I have in the cellForRowAtIndexPath: method.

    NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
    storyLink = [storyLink stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *sourceCode = [NSString stringWithContentsOfURL:[NSURL URLWithString:storyLink] encoding:NSUTF8StringEncoding error:&error];

    NSString *startPt = @"instant-gallery";
    NSString *startPt2 = @"<img src=\"";

    if ([sourceCode rangeOfString:startPt].length != 0) { //webpage has images
    // find the first  "<img src=...>" tag starting from "instant-gallery"
    NSString *trimmedSource = [sourceCode substringFromIndex:NSMaxRange([sourceCode rangeOfString:startPt])];
    trimmedSource = [trimmedSource substringFromIndex:NSMaxRange([trimmedSource rangeOfString:startPt2])];
    trimmedSource = [trimmedSource substringToIndex:[trimmedSource rangeOfString:@"\""].location];

    NSURL *url = [NSURL URLWithString:trimmedSource];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    cell.picture.image = image;

Someone suggested using NSOperationQueue. Would this way be a good solution?

EDIT:

  dispatch_queue_t someQueue = dispatch_queue_create("cell background queue", NULL);
    dispatch_async(someQueue, ^(void){

        NSError *error = nil;
        NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
        storyLink = [storyLink stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        NSString *sourceCode = [NSString stringWithContentsOfURL:[NSURL URLWithString:storyLink] encoding:NSUTF8StringEncoding error:&error];

        NSString *startPt = @"instant-gallery";
        NSString *startPt2 = @"<img src=\"";

        if ([sourceCode rangeOfString:startPt].length != 0) { //webpage has images
            // find the first  "<img src=...>" tag starting from "instant-gallery"
            NSString *trimmedSource = [sourceCode substringFromIndex:NSMaxRange([sourceCode rangeOfString:startPt])];
            trimmedSource = [trimmedSource substringFromIndex:NSMaxRange([trimmedSource rangeOfString:startPt2])];
            trimmedSource = [trimmedSource substringToIndex:[trimmedSource rangeOfString:@"\""].location];

            NSURL *url = [NSURL URLWithString:trimmedSource];
            NSData *data = [NSData dataWithContentsOfURL:url];
            UIImage *image = [UIImage imageWithData:data];

            dispatch_async(dispatch_get_main_queue(), ^(void){
                cell.picture.image = image;
            });
        });
        dispatch_release(someQueue);

        return cell;
    }

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:35:39+00:00Added an answer on June 13, 2026 at 4:35 pm

    For whatever that might be causing the lag, put it in the background thread. When you are ready to update your UI, update it on the main thread. Maybe you can give GCD at try –

    dispatch_queue_t someQueue = dispatch_queue_create("cell background queue", NULL);
    dispatch_async(someQueue, ^(void){
    
        NSURL *url = [NSURL URLWithString:trimmedSource];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *image = [UIImage imageWithData:data];
    
        dispatch_async(dispatch_get_main_queue(), ^(void){
            cell.picture.image = image;
        });
    });
    dispatch_release(someQueue);
    

    EDIT:

    When you have some process that might slow down your app, you want to put it in a background queue. To put them in background queue, you use dispatch_async:

    dispatch_aysnc(someQueue, ^(void){ 
    
    });
    

    where someQueue is the background queue you created and want work to be done. However, anything related to the UI needs to be on the main queue, or else some funky stuff can happen. That is why within that dispatch_async, we put another dispatch_async. This time, we specify the UI (cell.picture.image) needs to be updated on the main queue: dispatch_get_main_queue().

    Hope this clears it up a bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a stream of byte data from a telnet session via TcpClient.GetStream().ReadByte()
I have got an application, that is getting data via XML-files. During the parsing-part
I am submitting some form data via ajax and getting back a JSON array
I have a JQGrid which is loading data via AJAX and getting an JSON
I need a little help here getting data from mysql via PHP with AS3.
I am getting data via $_GET['value'] and I want that value to represent a
I am getting data from table in a database and I have created a
Sometime back I was getting alot of data via some API and I saved
I'm having problem with getting data from database via $wpdb : function nadji_sve_statuse() {
I'm accessing a Person entity using Azure Table Storage via OData (WCF Data Service).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.