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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:37:11+00:00 2026-06-17T11:37:11+00:00

Title itself is enough for my question I guess. However I will explain further

  • 0

Title itself is enough for my question I guess. However I will explain further here, consider I have a two view controller A and B. A is base and it is pushing B, In one situation I want the A to be intimated from B when one button is clicked in View (B). Objective C is allowing to call directly A view if I have that instance. I think it is not a good practice to do that. How this case should be handled..

thanks for your suggestions.

  • 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-17T11:37:12+00:00Added an answer on June 17, 2026 at 11:37 am

    IF by ‘A intimated from B’ you mean you want to invoke the A that was initially responsible for pushing B, you just go back to A using the ‘back’ button, or in code:

    [self.navigationController popViewController animated:YES];
    

    B doesn’t need a pointer to A, the Navigation Controller has that, and B has a pointer to the Nav Controller because the Nav Controller sets B’s navigationController property when it creates B.

    If you need to set a property in A based on some action in B, you should use a delegate to do that.

    In B, you make a property called delegate.

    In A, when you create B, set it’s delegate to A:

    ViewControllerB* vcB = [[ViewControllerB alloc] init];
    vcB.delegate = self;
    [self.navigationController pushViewController:vcB];
    

    Then in B you can call back to A via the delegate before the pop:

    [self.delegate sendMessageWithValue:someValue];
    [self.navigationController popViewController animated:YES];
    

    If you want to be extra-cautious, you can enclose the message-passing with:

    if ([self.delegate respondsToSelector:@selector(sendMessageWithValue:)]) { ... }
    

    To make this work without B knowing anything about A, other than that it is the delegate, B should declare a delegate protocol in the header (above @interface)

    @protocol BDelegateProtocol
    - (void) sendMessageWithValue:(int)someValue;
    @end
    

    When you declare the delegate property in B’s @interface, specify the protocol it is expected to follow:

    @property (nonatomic, weak) id <BDelegateProtocol> delegate;
    

    And in A’s @interface header, advertise that you follow that protocol:

    #import BViewController;
    
    @interface AViewController:UIViewController <BDelegateProtocol>
    

    This is the loose coupling you are after. B doesn’t have to import A’s header. It needs to know nothing about A other than that it conforms to B’s protocol specification.

    B does hold a pointer to A but it is a weak pointer. This is very important. If the delegate property was strong, B would increase the retain count of it’s delegate by 1. If the delegate also holds a strong pointer to B, then neither of them can ever get deallocated. B will always have a retain count of at least 1 while A exists, and likewise A will always have a retain count of 1 while B exists: neither can be destroyed.

    In this particular case that may not happen – A doesn’t need to retain B as it’s Nav Controller does – but it is a situation that can arise frequently as a delegate is very often the object that creates and owns the delegator. See “Use Weak References to Avoid Retain Cycles” in Apple’s Practical Memory Management

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

Sidebar

Related Questions

The title of the question is the error itself, but I will also include
I think that the question title explains itself :) Suppose that i have the
I think the title speaks for itself. I have a complex query with a
I guess the title speaks for itself. I am coding a C program on
I have a view controller that's embedded in a navigation controller. Therefore this view
Not sure if the title explains itself, but probably not! Anyway, I have 50
It is not as easy as the title itself. I have a table users
Question is the title itself. __doPostBack('<%=btnABC.UniqueID %>', '') and onClick=Button1_Click
Yes, I know the title is confusing enough, but here is what I want
Question is the title itself. I am new to MVC and I am now

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.