Note that there are some explanatory texts on larger screens.

plurals
  1. POchange Subview of superview through IBAction of Subview ios
    primarykey
    data
    text
    <p>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.</p> <p>in .h of MainViewController</p> <pre><code>@interface MainViewController : UIViewController { IBOutlet OneViewController *oneviewController; IBOutlet TwoViewController *twoViewController; } -(IBAction)goToView; @property (nonatomic, retain) IBOutlet OneViewController *oneviewController; @property (nonatomic, retain) IBOutlet TwoViewController *twoViewController; @end </code></pre> <p>in .m</p> <pre><code>@implementation MainViewController @synthesize oneviewController; @synthesize twoViewController; -(IBAction)goToView { [self.view addSubview:twoViewController.view]; } - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:oneviewController.view]; } </code></pre> <p>Ok this all works great, i am able to load both ViewControllers with xib and all their` buttons work etc. ..<br> But when I try...</p> <p>in .m of OneViewController</p> <pre><code>#import "MainViewController" ... [MainViewController.view addSubview:twoViewController.view]; ... </code></pre> <p>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!!</p> <p>I also tried this in the .m of OneViewController</p> <p>but it still crashed... although the build succeeded </p> <p><code>MainViewController* mySuperView = (MainViewController*)self.view.superview; TwoViewController *twoViewController; [mySuperView.view addSubview:twoViewController.view];</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload