![](/img/trans.png)
[英]Add a subview to a UIImageView that is the view outlet of a UIViewController in IB
[英]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.