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

The Archive Base Latest Questions

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

I have two view controllers, One and Two. I go from VC One to

  • 0

I have two view controllers, One and Two. I go from VC One to VC Two. On VC Two, I select some data that I store in an array. When I press the “Back” button on the navigation bar, I would like to send that array back to VC One.

What’s the best way to do this?

Thanks!

  • 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-15T06:09:30+00:00Added an answer on June 15, 2026 at 6:09 am

    Why not set up a delegate property on your second view controller that the first can register as. Then when the information is stored to the array, it can also be passed back to it’s delegate?

    To implement this

    At the top of your second view controllers .h file, you’ll need to declare an @protocol that the first view controller can implement. A protocol is simular to an interface in other languages. It’s a way of being sure an object implements certain methods, without needing to know specifically what that object is (view controller 1 in this case).

    @protocol MyDataDelegate
    
    - (void)recieveData:(NSArray *)theData
    
    @end
    

    and also declare a property for the delegate that the first view controller can set it’s self as before it presents the second

    @interface SecondViewController
    
    @property (nonatomic, weak) id<MyDataDelegate> delegate;
    

    Then in your first view controller .h file, implement the protocol as so

    in the .h file

    #import SecondViewController.h
    
    @interface FirstViewController <MyDataDelegate>
    
    //.....
    

    and in the .m, implement the methods declared in the protocol

    @implementation
    
    //.... usual methods
    
    - (void)recieveData:(NSArray *)theData {
    
        //Do something with data here
    }
    

    In order to set the first view controller as the delegate, you need to intercept the segue before it happens, by using a UIStoryBoardDelegate method. Add this to the first view controller

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        //Get a handle on the view controller about be presented
        SecondViewController *secondViewController = segue.destinationViewController;
    
        if ([secondViewController isKindOfClass:[SecondViewController class]]) {
            secondViewController.delegate = self;
        }
    }
    

    Now you have a pointer to the first view controller from the second, and can call methods and pass back the data, by calling the following method in the second view controller

    [self.delegate recieveData:theArrayData];

    You could also add another method to the protocol to notify the delegate that the second view controller is being dismissed if you wanted. Or use some of the suggestions from the other answers

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

Sidebar

Related Questions

I have two view controllers in a tabbar which can both edit data. Therefore,
I have two view controllers that allow changes to the Address Book. The first
I have a partial view that is shared between two controllers and I'm trying
I have two view controllers: view controller and viewcontroller2nd. I have UILabel in one
I have two View Controllers, one with a grid of buttons, and the second
I have two view controllers. In one of them I have a UITextField within
I have two tableview controllers showing CoreData objects. One is a detail view (with
I have created two viewController classes such that one is superclass of another.i have
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
I have two view Controllers in my project ViewController , SettingsView . Here I

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.