开发者

view controller hide problem

Hai , I have a created window based tabbar application. I created 5 tab bar item, one of the tab bar item is customer. After tapping customer i need to add another tab bar and 3 view controller such as customer list , select customer and invoice list .For this i have used a segment controller and 3 segment controller buttons.

I have created an IBaction:

-(IBAction) segmentedControlIndexChanged
{

  switch (self.segmentedControl.selectedSegmentIndex) 
{

        case 0:
    CustomerListviewController *customerListViewController=[[CustomerListviewControlle开发者_如何学Pythonr 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;
   }
}

But when i tap one segment controller then view appear with previous view in background. How can i solve this problem. If i have alternate idea instead of using segment controller ,i am agree to use . Plz any one help me to solve this or alternative solution.


Right now you do not remove any views before adding the new one, use the "removeFromSuperview" method to remove the subviews you no longer want. If you want complete tabula rasa after every switch try something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜