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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:34:30+00:00 2026-06-14T09:34:30+00:00

Possible Duplicate: viewDidLoad being called before didSelectRowAtIndexPath I am trying to pass variables over

  • 0

Possible Duplicate:
viewDidLoad being called before didSelectRowAtIndexPath

I am trying to pass variables over to the new view. I have the following code:

appDelegate *dataCenter = (AppDelegate*)[[UIApplication sharedApplication] delegate];

dataCenter.myVariable = [array objectAtIndex:indexPath.row];

in the

didSelectRowAtIndexPath

of the calling view. However, the issue that I have is that this variable is empty in the vewDidLoad function of the next view, simply because it fired off BEFORE the didSelectRowAtIndexPath of the calling view. I am using storyboard to link the views together. Both are UITableView.

If I hit back and then reselect the table element it is then set, granted that by the time I hit back and then selected again, the variable got set. Is there any way to for the order of execution? I really don’t want to do UI view switching on the back end.

Any help is greatly appreciated!

  • 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-14T09:34:31+00:00Added an answer on June 14, 2026 at 9:34 am

    How about saving the data to an NSUserDefaults at didSelectRowAtIndexPath
    And then at viewDidLoad read that saved data from NSUserDefaults.

    -(void) didSelectRowAtIndexPath {
        NSUserDefaults *infoSaved = [NSUserDefaults standardUserDefaults];
        [infoSaved setObject:myVariable forKey:@"myvariable"];
        [infoSaved:synchronize];
    
        // then call the new view to load
    }
    

    And in the new view that’s loaded:

    -(void) viewDidLoad {
        NSUserDefaults *infoSaved = [NSUserDefaults standardUserDefaults];
        myVariable = [infoSaved objectForKey:@"myvariable"];
    
        // and use your variable
    }
    

    Hope that helps

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

Sidebar

Related Questions

Possible Duplicate: How to pass data to detail view after being selected in a
Possible Duplicate: iOS - Passing variable to view controller I have two Viewcontrollers (ViewController1
Possible Duplicate: Trying to get tables next to each other horizontal I have two
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: Passing model objects from one view controller to another in a navigation
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Call Function in Underlying ViewController as Modal View Controller is Dismissed I've

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.