Use of undeclared type ‘UIContainerView’

1.1k views Asked by At

I’m using xcode 7 , I’ve a storyboard controller with an UIContainerView

When I’m trying to create an outlet to the controller there is this error "Use of undeclared type UIContainerView"

it’s not a bug of xcode 7 because there is the same error on xcode 6

i need to create an outlet because when i switch the segmented control i have to programmatically change the embed of the container

It's an error or i mustn't create an outlet for a container? It's seems that there is not something called UIContainerView in the library, it's strange

3

There are 3 answers

0
Midhun MP On BEST ANSWER

There is no such class called UIContainerView. You need to create an outlet of UIView and connect that to your container view.

You can switch the content of container view like:

// Property
@property (nonatomic, weak) IBOutlet UIView *container;
@property (nonatomic, strong) UIViewController *first;
@property (nonatomic, strong) UIViewController *second;

// Method that removes first vc from view and shows second vc
// Assumes first and second properties already initialized
- (void)showSecondVC
{
  // Removes first view controller
  [self.first.view removeFromSuperview];
  [self.first willMoveToParentViewController:nil];
  [self.first removeFromParentViewController];

  // Shows second view controller
  [self addChildViewController:self.second];
  [self.second didMoveToParentViewController:self];
  self.second.view.frame = self.container.bounds;
  [self.container addSubview:self.second.view];      
}
0
Ram Suthar On

UIContainerView is not a class, so you are getting error. Instead use UIView. Container view is actually a concept in storyboard, that allow you to do similar programming stuff:

  1. Initialise a second view controller
  2. Add it as child view controller
  3. Add its view at location of container view with same frame.

When you add a container view then all above stuff is done automatically. If you want to switch to different view controller then you will create multiple container view. Show and hide container views based on UISegmentedController's selectedIndex

0
Michael Peterson On

It is confusing because IB lablels it as UIContainerView, but it's type is really just a UIView.

enter image description here


enter image description here