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

The Archive Base Latest Questions

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

I have 2 view controllers, call them ViewController1 and ViewController2. A modal segue is

  • 0

I have 2 view controllers, call them ViewController1 and ViewController2. A modal segue is invoked from ViewController1 when I want to load ViewController2. I have a method in ViewController1 that needs to be called at some point when ViewController2 is showing. My idea is to have a property in ViewController2 that is a reference to ViewController1 so that I can get access to the method.

@property (strong, nonatomic) ViewController1 *vc1Reference;

This property would be set in the prepareForSegue method like so:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {   // 1
    if ([[segue identifier] isEqualToString:@"sequeToVC2"]) {            // 2
        ViewController2 *vc2 = segue.destinationViewController;          // 3
        vc2.vc1Reference = (ViewController1*)segue.sourceViewController; // 4
    }
}

However line 4 gives me this error: Implicit conversion of an Objective-C pointer to ‘int *’ is disallowed with ARC.

How am I supposed to set the reference?

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

    You are on the right track, but the correct way to do this is to use a delegate.

    You declare a delegate property in your vc2 @interface:

    @property (nonatomic, weak) id <vc2delegate> delegate   //[1] (in vc2.h)
    

    And you set the delegate in your prepareForSegue:

    vc2.delegate = self;    //[2] (in vc1.m)
    

    (‘self’ is the correct reference for vc1, from vc1)

    In vc2 you define a protocol, which is the method that you expect vc1 to respond to from vc2. Put this in vc2.h, above your @interface

    @protocol vc2delegate           //[3] (in vc2.h)
    - (void) delegateMethod;
    @end
    

    Then you have to ensure you implement that method in vc1. Also you need to let vc1 know to conform to the delegate. Import vc2 into vc1.h, and on your @interface line in vc1 add the protocol name in angle brackets:

    #import vc2.h
    
    @interface vc1 <vc2delegate>     //[4] (in vc1.h)
    

    This arrangement allows vc2 to pass a method to vc1 without having to #include vc1 or know anything else about it.

    more detail…

    1. This is the correct form of your

      @property (strong, nonatomic) ViewController1 *vc1Reference;
      

      Note the use of weak reference. You don’t want to make a strong reference as you don’t really want to have anything to do with the delegate except to know it can handle methods you specify in your protocol. The delegate is often the object that created the delegator, creating a strong reference back in the other direction can cause memory leaks as neither object can go out of existence.

    2. this is the correct form of your line:

      vc2.vc1Reference = (ViewController1*)segue.sourceViewController;
      

      Note that we are NOT using type/casting in 1 or 2. For maximum code reuse/decoupling we dont want to make any suppositions on the type of object at either end of the segue.
      I am assuming that your ‘prepareForSegue’ is in vc1. If it is not then the line would look like this:

      vc2.delegate = segue.sourceViewController
      
    3. This is the protocol declaration. It goes in the header file for vc2. vc2 is publishing it’s expectations of any object that chooses to become its delegate. vc2 will be sending messages according to this protocol so any delegate needs to respond in the correct way. You can guard against failure in vc2 by using this kind of message-passing

      if (self.delegate respondsToSelector:@selector('delegateMethod')
      {
          [self.delegate delegateMethod];
      }
      

      (that is an example of the kind of message passing you would use in vc2 to communicate back to vc1. you can obviously pass paremeters and get returned results back if need be)

    4. this is a helper for the compiler which can issue you with warnings if you fail to implement the protocol.

      Finally somewhere in your object definition you need to implement the method:

      - (void) delegateMethod 
      {
          // someaction;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have 4 view controllers (call them FirstView,SecondView,ThirdView,FourthView) which are created
I have two view controllers, call them viewA and ViewB All the action happens
I have two view controllers that allow changes to the Address Book. The first
I am implementing view controllers that shall have different behaviour. They have a common
Quick problem: I have an UITabBarController with 2 navigation controllers [lets call them Left
Hi I have a resetView method that resets my view too a default state
I have two view controllers. In one of them I have a UITextField within
I have two objects, both of which are view controllers. The first (Ill call
I have just noticed that my ViewController does not call init (See below) when
I have two view controllers in a tabbar which can both edit data. Therefore,

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.