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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:44:42+00:00 2026-06-15T20:44:42+00:00

Passing Data(String) from Child View Controller to Parent VC using easiest Way . i

  • 0

Passing Data(String) from Child View Controller to Parent VC using easiest Way .
i tried a Couple of ways , but got lost , can some one tell me the best way .

  • 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-15T20:44:44+00:00Added an answer on June 15, 2026 at 8:44 pm

    Srikanth is correct. If you have a segue from a view controller (our “first” view controller) to another (our “second” view controller), all you need to do is to create a property in the second one that points to the first one. You will just have the first view controller make sure to set that pointer before it performs the transition. Having done that, the second controller can update properties or invoke methods of the first controller.

    For details, see Configuring the Destination Controller When a Segue is Triggered in the View Controller Programming Guide for information on how to set a property in the second view controller (in this case, that property will be a weak pointer to the first controller) in prepareForSegue. Then, as Srikanth says, the second controller can use that pointer to update properties in the first one.

    So, in your second view controller, have a property (note carefully, it should be weak) that points back to the first view controller:

    In SecondViewController.h:

    @class FirstViewController;
    
    @interface SecondViewController : UIViewController
    
    @property (nonatomic, weak) FirstViewController *firstViewController;
    
    @end
    

    Then in the FirstViewController.m:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"YourSegueIdentifierHere"])
        {
            [segue.destinationViewController setFirstViewController:self];
        }
    }
    

    So, if your first view controller had, for example, a property of favoriteColor:

    @interface FirstViewController : UIViewController
    
    @property (nonatomic, strong) NSString *favoriteColor;
    
    @end
    

    Then, the second view controller could use its firstViewController property to update this favoriteColor, like so:

    self.firstViewController.favoriteColor = @"Blue";
    

    Clearly:

    1. Replace FirstViewController and SecondViewController with the appropriate class names;

    2. Make sure that your second view controller’s .m file does an #import of the first view controller’s .h; and

    3. Make sure you’ve specified a segue identifier in Interface Builder for your segue from the first controller to the second one and adjust the prepareForSegue above, replacing YourSegueIdentifierHere with your identifier.


    In iOS 6, you can also accomplish this via an unwind segue. You’d just have the prepareForSegue of the second view controller update the property of the unwind segue’s destination controller (i.e. the first controller). What’s nice is that unwind segues can go back an arbitrary number of levels, so for more complicated scenarios, it’s very nice. It is iOS 6, or higher, only, though.

    To do unwind segue’s, first you must define an unwind action in the first view controller (identified as such by the combination of the IBAction return type and the UIStoryboardSegue parameter), e.g.:

    - (IBAction)done:(UIStoryboardSegue *)segue
    {
        // do any clean up you want
    }
    

    Then, the second (or third or …) view controller can create an unwind segue by control-dragging in Interface Builder from a button to the exit icon in the scene’s dock. You can have the controller from which you’re unwinding do the logical prepareForSegue to pass information back to the first view controller.


    By the way, you used the terms “parent” and “child”, but I wanted to make it clear that I assumed that you were not talking about the more advanced topic of view controller containment, in which a view controller is invoking other view controllers to facilitate the presentation of a single screen of information (as opposed to transitioning between different scenes in an app). As rdelmar notes in our comments below, the terms “parent” and “child” controllers, strictly speaking, more properly imply that one is using view controller containment.

    Obviously, if you are using view controller containment, then clearly the discussion of segues, prepareForSegue, etc., don’t apply. Furthermore, a properly implemented container view controller guarantees that the child controllers can actually use the UIViewController property of parentViewController, without needing to define our own property to reference the parent. All you need to do is to cast/define parentViewController to be the right subclass, and then you can access your subclassed properties very easily.

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

Sidebar

Related Questions

Passing Data(String) from Child View Controller to Parent VC using Segues. Can Someone suggest
Passing data (simple string) from Controller to View I have in my controller: public
I'm passing data between my controller and my view using a ViewModel class. When
Is there any simple way of passing data (a simple string) from a content
I'm having trouble with ASP.NET MVC and passing data from View to Controller. I
I'm returning data from a HttpGet and then passing the string(s) into a Listview
I am having troubles passing data from the controller to the model in opencart(1.5.3).
In my MVC application I have a problem with passing data from view to
I tried to replicade a couple of posts here on stackoverflow, for passing data
My question is about passing data from kernel to a user space program. 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.