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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:02+00:00 2026-06-12T09:13:02+00:00

When I load my Master View it automatically loads a JSON feed with blog

  • 0

When I load my Master View it automatically loads a JSON feed with blog posts.

I have a refresh button on the top bar of my Master View. I have already connected it successfully to an IBAction and when clicked, I can output a string to log.

I am trying to get my view to reload the JSON feed when I click on the refresh button but that doesn’t work.

What am I doing wrong?

My ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UICollectionViewController {
    NSArray *posts;
}

- (void)fetchPosts;

- (IBAction)refresh:(id)sender;
@end

My ViewController.m

...

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self fetchPosts];
}

- (IBAction)refresh:(id)sender {

    [self fetchPosts];
}

- (void)fetchPosts
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://website.com/app/"]];

        NSError* error;

        posts = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.collectionView reloadData];
        });
    });
}
...
  • 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-12T09:13:03+00:00Added an answer on June 12, 2026 at 9:13 am

    The post is not being updated as you expect as it is being captured inside of the async block. If I remember correctly, instance variables are copied once passed into a block, so changes to them aren’t reflected outside of the async block unless they have the __block modifier.

    Try this,

    - (void)fetchPosts
    {
        __block NSArray *blockPosts = posts;
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://website.com/app/"]];
    
            NSError* error;
    
            blockPosts = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.collectionView reloadData];
            });
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have several JavaScript files which we load at the bottom of the master
I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>
I have a simple Partial View that I would like to automatically call a
I'm currently getting a Could not load type UI.Administration.Site.master error message and I'm not
I have a UIPopoverController with two view controllers inside of it. I'm building it
I have a ASP.Net web page with a grid view. I want to filter
Hi i have a MasterPage (ASP.Net MVC) which contains a couple of loads for
I have a MasterViewController in a MAster Detail aplication showind data in a UITableView.
i have the following loginview code in my site.master design <asp:LoginView ID=HeadLoginView runat=server EnableViewState=false>
I'm using a UISplitViewController, with a view that has a UITextView as the master

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.