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 9124957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:41:19+00:00 2026-06-17T06:41:19+00:00

I basically fetch images on JSON and then display it on the screen. On

  • 0

I basically fetch images on JSON and then display it on the screen. On my present code, it works fine except it displays the images after my while loop.

What I want is to display the image every time the loop is iterated. If possible, also display the images fading just like the Trailers.app by Apple.

Here’s my present code:

- (void)getNowShowingList2
{
    self.navigationItem.rightBarButtonItem = nil;

    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    activityIndicator.hidesWhenStopped = YES;
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
    [self navigationItem].rightBarButtonItem = barButton;
    [activityIndicator startAnimating];

    NSString *str = HOMEVIEW_URL;

    NSURL *url = [NSURL URLWithString:str];
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSString *jsonStr = [[[NSString alloc] initWithData:data
                                               encoding:NSUTF8StringEncoding] autorelease];

    // Checks for internet connectivity at startup
    if ([jsonStr isEqualToString:@""])
    {
        HideNetworkActivityIndicator();

        [self performSelectorOnMainThread:@selector(networkConnectivityCheck)
                                   withObject:nil
                                waitUntilDone:YES];
    }
    else
    {
        // Parse the string into JSON
        NSDictionary *json = [jsonStr JSONValue];

        // Get all object
        NSArray *items = [json valueForKeyPath:@"QUERY.DATA"];
        NSEnumerator *enumerator = [items objectEnumerator];

        NSArray *item;

        while (item = [enumerator nextObject])
        {
            [myMovieId      addObject:[item objectAtIndex:0]];
            [myMovieTitle   addObject:[item objectAtIndex:1]];

            NSString *genre = @"";

            if (genre == NULL)
            {
                genre = @"";
            }
            else
            {
                genre = [item objectAtIndex:2];
            }

            [myGenre    addObject:genre];
            [myCast     addObject:[item objectAtIndex:3]];
            [myPrice    addObject:[item objectAtIndex:4]];
            [myRuntime  addObject:[item objectAtIndex:5]];
            [myImageUrl addObject:[item objectAtIndex:6]];
            [myRating   addObject:[item objectAtIndex:7]];
            [myHits     addObject:[item objectAtIndex:8]];

            NSURL *url = [NSURL URLWithString:[item objectAtIndex:6]];
            NSData *data = [NSData dataWithContentsOfURL:url];

            if (data == nil) // checks if internet connection was lost while parsing & fetching
            {
                HideNetworkActivityIndicator();

                [self performSelectorOnMainThread:@selector(lostPrompt)
                                       withObject:self
                                    waitUntilDone:YES];

                break;
            }
            else
            {
                [myImage addObject:[UIImage imageWithData:data]];

                [self getMovieDetails:[item objectAtIndex:0]];
            }

            NSLog(@"O");
            [self displayButton2];
        }

        activityIndicator.hidden = YES;

        self.navigationItem.rightBarButtonItem = self.refreshButton;
    }

    [self performSelectorOnMainThread:@selector(versionCheck)
                           withObject:nil
                        waitUntilDone:YES];
}


- (void)displayButton2
{   
    int offset_x  = 19;
    int offset_y = 24;

    for (int i = 0; i < [myImage count] ; i++)
    {
        // compute x & y offset
        if (i % 3 == 0)
        {
            offset_x = 19;
        }
        else if (i % 3 == 1)
        {
            offset_x = 113;
        }
        else
        {
            offset_x = 208;
        }

        // Display Movie Thumbnail
        UIImage *imageView1 = [myImage objectAtIndex:i];
        CGRect myImageRect1 = CGRectMake(offset_x, offset_y, MOVIE_THUMBNAIL_W, MOVIE_THUMBNAIL_H);

        UIButton *button1 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        button1.frame = myImageRect1;
        button1.backgroundColor = [UIColor clearColor];
        [button1 setBackgroundImage:imageView1 forState:UIControlStateNormal];
        button1.tag = i;
        [button1 addTarget:self
                    action:@selector(imageButtonPressed:)
          forControlEvents:UIControlEventTouchUpInside];
        [scrollview addSubview:button1];

        // Quick Buy Image
        UIImage *buy_image = QUICK_BUY_BUTTON;
        CGRect myImageRect2 = CGRectMake(offset_x + (MOVIE_THUMBNAIL_W-QUICK_BUY_BUTTON_W-2), offset_y + 2, QUICK_BUY_BUTTON_W, QUICK_BUY_BUTTON_H);

        UIButton *button2 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        button2.frame = myImageRect2;
        button2.backgroundColor = [UIColor clearColor];
        [button2 setBackgroundImage:buy_image forState:UIControlStateNormal];
        button2.tag = i;
        [button2 addTarget:self
                    action:@selector(quickBuyButtonPressed:)
          forControlEvents:UIControlEventTouchUpInside];
        [scrollview addSubview:button2];

        // increment offset
        if (offset_x == 208)
        {
            offset_y += 150;
        }
    }

    if ((offset_x == 19) || (offset_x == 113))
    {
        offset_y += 158;
    }

    // Adjust scroll view
    [scrollview setContentSize:CGSizeMake(0, offset_y + 10)];

    // adjust background
    [background setFrame:CGRectMake(13, 13, 294, offset_y - 17)];
    backgroundHeightAdjust = offset_y - 17;
}

In the long run, I’m also planning to use AFNetworking as it may help with the effect I want to achieve.

  • 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-17T06:41:21+00:00Added an answer on June 17, 2026 at 6:41 am

    Parse the JSON in background thread. Every time you need to load an image, set it to the image imageView in the main thread.

    ...
    // Parse the string into JSON
    [self performSelectorInBackground:@selector(parseJson:) withObject:jsonStr];
    // ...
    
    -(void)parseJson:(NSString*)jsonStr{
    
          // Parse Json ...
          // Show image on main thread
          [self performSelectorOnMainThread:@selector(showImage:)
                                 withObject:image
                              waitUntilDone:NO];
    
    }
    
    -(void)showImage:(UIImage *)image{
          imageView.image = image;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically the code inside the displayCharityList () works. I decided to put that code
Basically, the code below will generate divs which are then captured using the jquery
basically i would like to display .doc file in WWW, i've tried to fetch
I am basically wanting to fetch an IDIctionary from a place which is global
we are tasked with basically emulating a browser to fetch webpages, looking to automate
Started recently, basically every time I try to fetch or commit it gives me
I have a simple question - basically I want to fetch all ActiveRecords of
Having some issues, basically I have a random image gallery. This is the code
I am trying to populate instagram images using backbone, I have basically 3 models
I'm working on a website just now, and basically it has 2 images next

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.