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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:23:30+00:00 2026-05-23T10:23:30+00:00

So i have two view controller in FirstViewController and SecondViewController in FirstViewController NSMutableArray *array;

  • 0

So i have two view controller in FirstViewController and SecondViewController

in FirstViewController

 NSMutableArray *array;

create a property for it and synthesised it

in SecondViewController

NSMutableArray *arraySecond;

create a property and synthesized it
then I try to do something like this (after arraySecond is set to something like a b c d )

FirstViewController *FV = [[FirstViewController alloc]init];
FV.array = arraySecond;
[FV release];

I try to do that but when I try to print out the array from firstviewcontroller it is being set to (null) why is it doing that and what can i do to fix it?

  • 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-23T10:23:31+00:00Added an answer on May 23, 2026 at 10:23 am

    You are creating an instance of FirstViewController, setting the value of array and then releasing that instance which will deallocate the object. So the entire effort is wasted. Since this is in the SecondViewController, I am assuming the FirstViewController exists by this time so you shouldn’t be setting the array of a new instance of FirstViewController but try to pass it to the existing instance. Since you already have a property declared to share across the view controllers, we will make use of it.

    Do this when instantiating the SecondViewController instance in FirstViewController,

    SecondViewController * viewController = [[SecondViewController alloc] init];
    
    self.array = [NSMutableArray array];
    viewController.arraySecond = self.array;
    
    [self.navigationController pushViewController:viewController animated:YES];
    [viewController release];
    

    Now the array is shared across the view controllers. Do not initialize the arraySecond property elsewhere so that both of them keep pointing to the same object and the changes your make to arraySecond are visible to the FirstViewController instance. After coming back to the FirstViewController instance, access the values you’ve added using array property.

    Alternatives to object sharing are delegate mechanism and notifications. You can look into them too. For now, this should work.

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

Sidebar

Related Questions

Hi i have two view controller: FirstViewController and SecondViewController FirstViewController.h #import <UIKit/UIKit.h> @interface FirstViewController:
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
I have two view controllers: firstViewController and secondViewController. On the firstViewController I have a
lets say i have two view controllers, firstViewController and secondViewController. The firstViewController is supposed
i have got two view. First: FirstViewController Second: SecondViewController FirstViewController is my UINavigationController 's
I have two view controller classes in my application delegate. I can change from
I have two View Controllers: TableViewController (which is used as a modal view controller)
I am trying to create a two view, single controller application as follows: I
So I have two view controller that I load on the app delegate when
The Problem: I have two View Controllers loaded into a root View Controller. Both

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.