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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:35:27+00:00 2026-05-23T20:35:27+00:00

I tried to find a solution here but was unable to, basically I have

  • 0

I tried to find a solution here but was unable to, basically I have an interactive subview that I need to switch to a new interactive subview from within the subview. I am able to change subviews easily with an IBAction in the main view, but I have been unsuccessful changing the view from within the subview. Here’s the code… which should make what I am trying to accomplish more clear.

in .h of MainViewController

@interface MainViewController : UIViewController {
    IBOutlet OneViewController *oneviewController;
    IBOutlet TwoViewController *twoViewController;
}

-(IBAction)goToView;

@property (nonatomic, retain) IBOutlet OneViewController *oneviewController;
@property (nonatomic, retain) IBOutlet TwoViewController *twoViewController;

@end

in .m

@implementation MainViewController

@synthesize oneviewController;
@synthesize twoViewController;

-(IBAction)goToView {   
    [self.view addSubview:twoViewController.view];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view addSubview:oneviewController.view];  
}

Ok this all works great, i am able to load both ViewControllers with xib and all their` buttons work etc. ..
But when I try…

in .m of OneViewController

#import "MainViewController"

...
[MainViewController.view addSubview:twoViewController.view];  ...

this does not work, I have tried a variety of things, by adding the twoViewController to the .h of oneViewController, but it crashed… I am still very new to all this so It is likely I am missing the obvious. Thanks for help!!

I also tried this in the .m of OneViewController

but it still crashed… although the build succeeded

MainViewController* mySuperView = (MainViewController*)self.view.superview;
TwoViewController *twoViewController;
[mySuperView.view addSubview:twoViewController.view];

  • 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-23T20:35:27+00:00Added an answer on May 23, 2026 at 8:35 pm

    This action is being done in the wrong place. If you are trying to add a subview to your MainViewController, you should really handle that inside of MainViewController.m. You are calling:

    [MainViewController.view addSubview:twoViewController.view];

    but MainViewController.view is a static instance of view. If you want to keep it as is, and assuming OneViewController is already a subview on MainViewController, you should do something like this:

    UIView *main = [OneViewController.view superview];
    [main addSubview:twoViewController.view];

    This is pretty dangerous though because you’re not guaranteed to have a superview for this view. I’d just handle all of this inside MainViewController. No controller should have the power to add a subview to another controller unless it had an instance of MainViewController.

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

Sidebar

Related Questions

I've tried Googling and searching stackoverflow, but have yet to find a solution too
I have been trying to find a solution for past few hours but unable
I tried to find a solution to my problem already in google and here
I tried to find a solution but I didn't found what I was searching
I've tried to find a solution for my problem, but my knowledge in this
I tried to find an easy solution for the following. I have a main
I've tried various things and googled multiple hours but couldn't find a solution to
I've seen a lot of similar question here but couldn't find the solution. I
simple question maybe but can't find solution. I have button for refresh/update some contents
I've researched most of the questions here but did not find a viable solution.

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.