Use of undeclared type ‘UIContainerView’

对着背影说爱祢 提交于 2019-12-13 08:07:32

问题


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


回答1:


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];      
}



回答2:


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





回答3:


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



来源:https://stackoverflow.com/questions/31049928/use-of-undeclared-type-uicontainerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!