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

  • Home
  • SEARCH
  • 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 372223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:11:24+00:00 2026-05-12T14:11:24+00:00

My app has a main screen that the user always starts at, and from

  • 0

My app has a main screen that the user always starts at, and from which I want to display other views programmatically. I set up the app identically to the approach in “Beginning iPhone Development” Ch. 6, which is to use a RootViewController that loads in other view controllers.

The book uses a button to trigger loading the next view controller, but in my app I need to swap controllers at the end of function calls and to share data (processed UIImages, etc) between views. I am not using a tab bar or navigation controller.

What I’m wondering is, should I just make my MainViewController the root controller and presentModalViewControllers from there? I’d like to keep the root model but I don’t quite understand how to hook it all up and share data. I’ve seen posts that mention using protocols and notifications but I haven’t wrapped my head around it yet. Any advice is 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-05-12T14:11:24+00:00Added an answer on May 12, 2026 at 2:11 pm

    What you want to do is add a Cocoa property in your main view controller that references the object instances which you want to share with subordinate view controllers.

    For example, if we want to share an NSArray, we specify its property in the main view controller header:

    @interface MainViewController : UIViewController {
      NSArray *myArray;
    }
    
    @property (nonatomic, retain) NSArray *myArray;
    
    @end
    

    In the implementation, add the @synthesize directive and remember to release the array in -dealloc:

    @implementation MainViewController
    
    @synthesize myArray;
    
    ...
    
    - (void) dealloc {
      [myArray release];
      [super dealloc];
    }
    
    @end
    

    You also want to add this property to view controllers that are subordinate to the main view controller, in the exact same way. In their headers, specify the same variable name and property description.

    In your main view controller, when you are ready to push a subordinate view controller, you set the subordinate view controller’s property accordingly just before pushing:

    - (void) pushSubordinateViewController {
      SubordinateViewController *subVC = [[SubordinateViewController alloc] initWithNibName:@"SubordinateViewController" bundle:nil];
      subVC.myArray = self.myArray; // this sets the sub view controller's myArray property
      [self.navigationController pushViewController:subVC animated:YES];
      [subVC release];
    }
    

    Likewise in your subordinate view controller, it will need to set its subordinate’s array property accordingly, just before it pushes its own sub-sub-view controller.

    By setting references in this way, each view controller is pointed at the same array, containing the desired elements.

    To use the array, just call self.myArray, e.g. [self.myArray objectAtIndex:index] to get an object at a given index.

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

Sidebar

Related Questions

I am creating an app that has three tabs on the main screen. Each
When my iPhone app starts up, the main screen has a keyboard. Currently the
My app has a main login/password screen where user enters credentials and submits the
I'm making an app which has a flow roughly as below: User starts on
My app has a screen where keyboard is always visible. The main element of
My app has a login screen before a user goes into the main view.
My app has a splash screen activity and that starts an intent for the
My swing app has a main window which has sever buttons. This JFrame is
I'm working on an app that has a status menu and from that menu
I am working on an Android app that has multiple screens the user will

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.