简体   繁体   English

将UIViewControllers视图添加为另一个UIViewController视图的子视图

[英]Add UIViewControllers View as a subView of another UIViewController view

I have a UiView called TestView which I have added as a subView of my NumberViewController. 我有一个称为TestView的UiView,它已作为NumberViewController的子视图添加。

On start of my app, My rootViewController is PaperViewController, this has some UIButtons which I have added through xib, Now I wanted to add NumberViewController's view as a subView of PaperViewController, so I did this 在我的应用程序启动时,我的rootViewController是PaperViewController,它具有我通过xib添加的一些UIButton,现在我想将NumberViewController的视图添加为PaperViewController的子视图,所以我做到了

 NumberViewController = [[NumberViewController alloc] initWithNibName:@"NumberViewController" bundle:nil];
    NumberViewController.delegate = self;
    [self.view addSubview:NumberViewController.view];
    NumberViewController.view.backgroundColor = [UIColor clearColor];
    NumberViewController.view.hidden = YES;

Now this is hidden because, I will unhide it on click of some button and then I will show NumberViewContrller's view.This all works fine. 现在将其隐藏,因为我将在单击某个按钮时取消隐藏它,然后将显示NumberViewContrller的视图。

But suppose I added some buttons in PaperViewController through code, and then unhide NumberViewController's view , then both views overlap. 但是,假设我通过代码在PaperViewController中添加了一些按钮,然后取消隐藏NumberViewController的视图,则两个视图重叠。

I am not understanding what is the problem, and what mistake I am making. 我不明白问题出在哪里,我犯了什么错误。 So friends please help me out 朋友们请帮帮我

Regards Ranjit. 问候兰吉特。

Add UIView in Header: 在标题中添加UIView:

@property (weak, nonatomic) IBOutlet UIView *addChildView;

In - (void)viewDidLoad - Method do this: - (void)viewDidLoad方法中执行以下操作:

  ChildViewController *nonSystemsController = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];

    nonSystemsController.view.frame = self.addChildView.bounds;    
    [self.addChildView addSubview:nonSystemsController.view];

    [nonSystemsController didMoveToParentViewController:self];
[self addChildViewController:nonSystemsController];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将子视图添加到UIImageView,它是IB中UIViewController的视图出口 - Add a subview to a UIImageView that is the view outlet of a UIViewController in IB 如何将UIViewController的视图作为子视图添加到UITableViewCell? - How to add a UIViewController's view as a subview to a UITableViewCell? 在UIViewController视图上对子视图进行动画处理 - Animate subview on UIViewController view 在另一个视图控制器中将视图控制器添加为子视图 - Add a view controller as a subview in another view controller 带有SubView的tableView的容器视图或UIViewController - Container View or UIViewController for tableView with SubView UIViewController作为其他视图控制器的子视图 - UIViewController as a subview for other view controllers 是否可以将UIViewController的视图添加到另一个UIViewController的视图中? - Is it advisable to add a UIViewController's view to another UIViewController's view? 将集合视图控制器添加到另一个控制器作为子视图 - add a collection view controller to another controller as subview 如何添加子视图以使其与另一个视图重叠? - How to add subview so that it overlaps another view? 从另一个视图控制器向视图控制器添加子视图 - add subview to a view controller from another view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM