我创建了一个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任何人帮我解决这个或替代解决方案。
答案 0 :(得分:0)
现在,在添加新视图之前,您不会删除任何视图,请使用“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;
}
}