视图控制器隐藏问题
问题描述:
Hai, 我有一个创建的基于窗口的标签栏应用程序。我创建了5个标签栏项目,其中一个标签栏项目是客户。点击客户后,我需要添加另一个标签栏和3视图控制器,如客户列表,选择客户和发票清单。为此,我使用了段控制器和3段控制器按钮。视图控制器隐藏问题
我已经创建了一个IBAction为:
-(IBAction) segmentedControlIndexChanged
{
switch (self.segmentedControl.selectedSegmentIndex)
{
case 0:
CustomerListviewController *customerListViewController=[[CustomerListviewController alloc]init];
[self.view addsubView:customerListViewController.view];
break;
case 1:
SelectCustomerviewController *selectCustomerviewController =[[ SelectCustomerviewController alloc]init];
[self.view addsubView:*selectCustomerviewControllerr.view];
break;
case 2:
InvoiceListViewController *invoiceListViewController=[[ InvoiceListViewController alloc]init];
[self.view addsubView:invoiceListViewController.view];
break;
default:
break;
}
}
但是,当我一个轻按段控制器然后查看与在背景前视图出现。 我该如何解决这个问题。如果我有替代想法而不是使用段控制器,我同意使用。 Plz任何人都可以帮助我解决这个或替代解决方案。
答
现在您在添加新视图之前不删除任何视图,请使用“removeFromSuperview”方法删除您不再需要的子视图。如果你想在每个开关之后使用完整的tabula rasa,请尝试如下所示:
-(IBAction) segmentedControlIndexChanged
{
// Remove all subviews of the main view of the view Controller
for (UIView *view in [self.view subviews]) {
[view removeFromSuperview];
}
switch (self.segmentedControl.selectedSegmentIndex) {
case 0:
CustomerListviewController *customerListViewController=[[CustomerListviewController alloc]init];
[self.view addsubView:customerListViewController.view];
break;
case 1:
SelectCustomerviewController *selectCustomerviewController =[[ SelectCustomerviewController alloc]init];
[self.view addsubView:*selectCustomerviewControllerr.view];
break;
case 2:
InvoiceListViewController *invoiceListViewController=[[ InvoiceListViewController alloc]init];
[self.view addsubView:invoiceListViewController.view];
break;
default:
break;
}
}