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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:46:09+00:00 2026-06-15T03:46:09+00:00

After I push myViewController onto the navigation stack I make a simple network request

  • 0

After I push myViewController onto the navigation stack I make a simple network request for some data that populates a few fields on myViewController. I don’t want this request to block the main thread so I make it using performSelectorInBackground. When the request returns I use performSelectorOnMainThread to update the UI.

This approach works fine except for abandoning the request. Say the user pushes the view controller, the network request starts, then the user immediately pops the view controller and does something else in the app. In this case the network request comes back to a non-existent object. How can I handle this case?

I’ve considered a more robust networking layer where each request has a delegate the handles the response. Using this architecture I could nil out the delegate when the view controller is popped hence avoiding the problem of the request returning to nothing. I’m not sure if this is the best way to go.

  • 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-15T03:46:10+00:00Added an answer on June 15, 2026 at 3:46 am

    I don’t want this request to block the main thread so I make it using
    performSelectorInBackground.

    So you’re making a synchronous request — one that’ll block the thread that it’s running on. Instead of doing that, make the request asynchronous using, for example, +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]. You can then make the request from whatever thread you like, including the main thread — no need for -performSelectorInBackground:. When the connection changes state, your delegate will be notified using the NSURLConnectionDelegate protocol. This way, you can send a -cancel message to the connection to stop it.

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

Sidebar

Related Questions

I did push origin master and after that I have an error: $ git
Can anyone confirm that after changing the Apple Push Certificate to follow the new
I have a UINavigationController with which I push UIViewControllers onto using pushViewController:animated: . After
I would expect that after I push a view controller I then need to
I use git under window and I want do some operation after each push,
Usually when we push viewcontroller, we will create object for view controller, after that
After pushing to a git repo, I got this error: [trusktr@starlancer bml]$ git push
How can we get Push Queue Tasks scheduled for execution ASAP after enqueuing? Do
I'm writing a tool which will push changes to database after commit to svn.
I have declared: queue<int, list<int> > Q After a series of calls: Q.push(37); Q.pop();

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.