View container using storyboard, interaction, and view

I am trying to implement a view layout with two simple containers side by side in the style of an iPad panel.

I read numerous examples and, of course, the link to the Apple View controller for view controllers and in general, but I have the strangest problem, which I hope has a simple explanation.

I added two side-by-side view containers, each of which will have a viewcontroller with a different background color, one Round Rect button and a shortcut. And for testing, I also added a Round Rect button to the "mainViewController".

So rightly and simply. Each view is loaded into the container view, but I can’t interact with any of them (when the button is pressed, NOTHING happens, the blue highlighting is not highlighted, so there is no question of delegation or any action using the buttons, nothing like this has been implemented). However, pressing the button that I installed in the "mainViewController" holding two containers works flawlessly (as always). Another strange thing: the background color does not appear on container views ?! Buttons and tags only.

The program is as follows:

Files: ViewController.h and .m ("mainViewController") sidebarViewController.h and .m (nothing has changed in these files, UIViewController) resultsViewController.h and .m (nothing has changed in these files, UIViewController) AppDelegate.h and. m (no change) Storyboard

ViewController.h, outputs created and connected to each type of container in the storyboard.

#import <UIKit/UIKit.h> #import "sidebarViewController.h" #import "resultsViewController.h" @interface ViewController : UIViewController @property (nonatomic, weak) IBOutlet UIView *sidebarView; @property (nonatomic, weak) IBOutlet UIView *resultsView; @end 

The storyboard identifier set in both the sidebarViewcontroller and the Resultsview controller in the storyboard.

ViewController.m, all that is done in the book (or probably not, but at least it seems to me)

 #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize sidebarView,resultsView; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIStoryboard *storyboard = self.storyboard; sidebarViewController *sideVC = [storyboard instantiateViewControllerWithIdentifier:@"SidebarViewController"]; resultsViewController *resultsVC = [storyboard instantiateViewControllerWithIdentifier:@"ResultsViewController"]; //sidebarViewController *sideVC = [[sidebarViewController alloc]init]; //rresultsViewController *resultsVC = [[resultsViewController alloc]init]; [self addChildViewController:sideVC]; sideVC.view.frame = self.sidebarView.frame; [self.sidebarView addSubview:sideVC.view]; self.sidebarView.userInteractionEnabled = YES; [sideVC didMoveToParentViewController:self]; [self addChildViewController:resultsVC]; resultsVC.view.frame = self.resultsView.frame; [self.resultsView addSubview:resultsVC.view]; self.resultsView.userInteractionEnabled = YES; [resultsVC didMoveToParentViewController:self]; } 

(I also had self.xxxxView, and also had the addChildViewController statement in order)

Well, that’s why my suspicion, of course, is related to the hierarchy of views, the views behind the view of the rootViewController and therefore are shown only non-interactively. What (if something) needs to be done in the App delegate to make this work? Or did I do something else wrong with this code?

Edit: I found another key to what might be wrong: when I turned off Auto View for storyboards, the views displayed and worked (!), But were completely distorted, but now at least I get the correct background color and the buttons work . Does anyone know how to fix this without disabling autoscaling? since I assume that I should do all my layout programmatically then ?: (

Many thanks,

+8
ios uiviewcontroller uiview storyboard parent-child
source share
1 answer

All that you have is not necessary, and it is probably causing problems. When you add container views to IB, it automatically creates these built-in view controllers for you (and resizes them as the size of the container view). Did you get them? All you have to do is change their classes to the classes of your subclasses. If you need to access these controllers from your "main" view controller, you can get a link to them from the childViewControllers property.

+2
source share

All Articles