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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:02:37+00:00 2026-05-25T00:02:37+00:00

Suppose you have an iOS app with a UINavigationController with three UIViewControllers pushed onto

  • 0

Suppose you have an iOS app with a UINavigationController with three UIViewControllers pushed onto it: vc1, vc2 and vc3.

vc1 wants to get notified of when something happens on vc2 and/or vc3. For example, when something gets saved on vc2 or vc3, update vc1 and automatically pop back to vc1. Easy. Just have vc2 or vc3 fire an event and have it be caught by vc1. Well, when the time comes to pop back to vc1 the other two vc’s won’t get garbage collected because they hold a reference via the event subscription.

What’s the best way to resolve this and get everything cleaned up when vc1 subscribes to an event on vc2, similarly vc2 to vc3?

Only thing I can think of is to define a public CleanUp() method so that when the nav controller pops back to vc1 (and vc1 will have to detect this scenario somehow) it will call vc2.CleanUp(). If you had X number of vc’s that would be a lot of cleanup that you’d have to write ’cause you’d have to, in a sense, bubble up the call through the line of popped vc’s. Yuck.

How would you do this traditionally in obj-c and also, how would you do this in MonoTouch?

  • 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-25T00:02:37+00:00Added an answer on May 25, 2026 at 12:02 am

    I am using the scenario you are describing above quite frequently. This is how I handle it:

    Controller vc1 pushes vc2 onto the navigation stack, after it has subscribed to vc2’s SaveClicked event. So I want to pop vc2 when this event occurs. Now, since vc2 will be popped when the SaveClicked event will be triggered, it suits us because we know that the event will only be used once. I also use anonymous methods for these situations when not much logic is needed, to keep things compact.

    Inside vc1:

    vc2 = new UIViewController(); //vc2 is a class variable
    EventHandler vc2SaveClickedHandler = null;
    vc2SaveClickedHandler = delegate(object sender, EventArgs e) {
    
        // Unsubscribe here
        vc2.SaveClicked -= vc2SaveClickedHandler;
        // Or, we could do:
        // UIViewController vc2Sender = sender as UIViewController;
        // vc2Sender.SaveClicked -= vc2SaveClickedHandler;
    
        // do some stuff
    
        // Pop vc2
        vc2.NavigationController.PopViewControllerAnimated(true);
    
    }
    vc2.SaveClicked += vc2SaveClickedHandler;
    this.NavigationController.PushViewControllerAnimated(vc2, true);
    

    So you can do the same for vc2 and vc3 and so on…

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

Sidebar

Related Questions

I'm making an iOS app which is OpenFeint enabled. I have managed to get
Suppose I have three models: Student , SchoolClass , and DayOfWeek . There is
I have a textfield in my iOS app where the user is supposed to
I have 2 separate iOS projects in xcode 4. One is APP which is
I am developing an app for iOS 5, which have to run in landscape
I have an ad-hoc deployment of my iOS game, which includes in-app purchase. It
I have an ASP.NET MVC 3 website that communicates with my iOS app via
I have a simple question about event handling in iOS applications... suppose you have
Suppose that I have an app called A . Bundle Identifiers must be unique
I am learning iOS and I have written a simple iPhone app using iOS

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.