2011-03-28 111 views
0

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任何人都可以幫助我解決這個或替代解決方案。

回答

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; 
    } 
}