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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:49:31+00:00 2026-05-26T17:49:31+00:00

I have a view based app (not navigation or tab based…) My main view

  • 0

I have a view based app (not navigation or tab based…)

My main view controller is called from the app delegate and initiated from a xib.

Then I use presentModalViewController to bring another view on the screen with it’s own xib and view controller.

I have no problems passing data to that view controller.

However, when I dismiss the second view controller, I want to send data back to the main view controller for my app, but I just can’t figure out how to reference it. Actually, I’d like to call a method in the main view controller if possible.

I’ve been struggling with this a bit and have found suggestions online but I just can’t seem to get it to work. I’m hoping someone can provide the sample code to do this.

P.s. is this “main view controller” still referred to as a “root view controller” or is that term only used when dealing with a view controller stack (i.e. navigation or tab view controller)

EDIT:
I’m sure Bryan’s solution would work so I have accepted as answer. However I ended up using NSNotificationCenter to get this to work and I find it a bit simpler to understand as a beginner

  • 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-26T17:49:31+00:00Added an answer on May 26, 2026 at 5:49 pm

    You can use the delegation pattern. In your modal view controller’s header file, create an interface for a new delegate protocol…

    @protocol ModalViewControllerDelegate <NSObject>
    
    - (void)sendData:(Data *)someData;
    
    @end
    

    …and give your ModalViewController a new instance variable that implements this protocol:

    @property (nonatomic, assign) id<ModalViewControllerDelegate> delegate;
    

    Your main view controller should implement this protocol…

    @interface MainViewController : UIViewController <ModalViewControllerDelegate> {
    

    …and set itself as the delegate before it presents the modal view controller:

    ModalViewController *modalViewController = [[[ModalViewController alloc] init] autorelease];
    [modalViewController setDelegate:self];
    // Present modal view controller
    

    The main view controller should implement the delegate protocol’s method:

    - (void)sendData:(Data *)someData {
        NSLog("I have just received some data: %@", someData);
    }
    

    Then inside your modal view controller, you can simply call the following method whenever you want to send data back to the main view controller:

    [delegate sendData:someData];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 25 views in a navigation based app. From the 25th view
I have a view based app that works well. (In other words, I'm not
I have a navigation based app where a certain pushed view has a nice
In my app I have a UIWebView-based view controller showing info and credits about
I have a tab bar + navigation based app and I'd like to launch
I have a simple iPhone app based on a navigation controller. There are two
I have a modal view controller whose view comes from a XIB. I want
I created a navigation controller based app. The view that opens up below the
My app is a Navigation based application. The main menu contains the list view
I am building a Calendar app. I have Navigation based app template. Navigation controller

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.