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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:22:18+00:00 2026-05-15T23:22:18+00:00

So I have a ViewController Class which is my first view, I then add

  • 0

So I have a ViewController Class which is my first view, I then add a subview to it, pseudo code code below;

ViewController2 *viewController2 = [[ViewController2 alloc] init]; 
[self addSubview:viewController2.view];

My question is, in ViewController1, I have a method that does an animation and removes the view. How can I call that method from a button on ViewController 2?

I tried doing something like in ViewController2…

ViewController1 *viewController1 = [[ViewController1 alloc] init]; 
[viewController1 back]; //Trying to call method in other class from ViewController2

And its funny because in the “back” method on ViewController1,I have an NSLog statement, and it works, but none of the other code works. So I know the method is getting called from my other class, but only the NSLog part of it executes? Any Suggestions.

SO basically I want to call a method of ViewController1 from ViewController2

  • 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-15T23:22:19+00:00Added an answer on May 15, 2026 at 11:22 pm

    You can’t create a second instance of ViewController1 and get the effect you’re looking for. You need to call it on the instance that has already been created.

    In this case, you can accomplish it by creating an ivar in ViewController2 to remember who the parent is and assign it when you add in the other VC. Let’s say you call the ivar owningViewController1. Add a property for it in ViewController2.h and synthesize it at the top of ViewControler2.m, then change your example to:

    ViewController2 *viewController2 = [[ViewController2 alloc] init]; 
    [self addSubview:viewController2.view];
    [viewController2 setOwningViewController1:self];
    

    Then, don’t bother creating a new ViewController1 instance, just use the one saved:

    [owningViewController1 back];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could do this by applying multiple mappings to your… May 16, 2026 at 6:20 pm
  • Editorial Team
    Editorial Team added an answer would this fit your needs? http://wordpress.org/extend/plugins/filebrowser/ looks clean and you… May 16, 2026 at 6:20 pm
  • Editorial Team
    Editorial Team added an answer If want to generate something similar to MSDN, you could… May 16, 2026 at 6:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Example: I have 10 view controllers, which are all allocated and initialized in the
Ok heres the situation. I have a View controller class that serves as the
I have a TableView controller class that uses a fetched results controller to display
I've my own class which should do the request and the data processing (parsing).
I have the UIApplicationDelegate protocol in my main AppDelegate.m class, with the applicationDidBecomeActive method
Dear scholars, code gurus. My question is rather simple, I have been searching and
I have a viewController containing the following method: - (IBAction) playMovie { NSURL *url
I'm having the following issue: I have a tab-style app. Eacht tab has its
I created a tab bar application, and I make the first tab a table.
I created a class to launch the MailComposer so that my iPhone app would

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.