繁体   English   中英

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

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

我有一个称为TestView的UiView,它已作为NumberViewController的子视图添加。

在我的应用程序启动时,我的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;

现在将其隐藏,因为我将在单击某个按钮时取消隐藏它,然后将显示NumberViewContrller的视图。

但是,假设我通过代码在PaperViewController中添加了一些按钮,然后取消隐藏NumberViewController的视图,则两个视图重叠。

我不明白问题出在哪里,我犯了什么错误。 朋友们请帮帮我

问候兰吉特。

在标题中添加UIView:

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

- (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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM