[英]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.