修正方案,之前的方案方案会导致队列不断增加,这边需要注意的是,当view为nil时 不会调用removeFormSuperView 所以这个时候不会出现异常。队列不断增加会导致内存溢出。

  • (void)clickToChose:(id)sender

{

UIButton *button = (UIButton *)sender;

oneViewController *oneView = [self.storyboard instantiateViewControllerWithIdentifier:@"one"];

twoViewController *twoView = [self.storyboard instantiateViewControllerWithIdentifier:@"two"];



switch (button.tag) {

    case 1000:

        

        

        [self.subView addSubview:oneView.view];

        [currentView removeFromSuperview];

        currentView = oneView.view;

        

        break;

    case 1001:

        [self.subView addSubview:twoView.view];

        [currentView removeFromSuperview];

        currentView = twoView.view;

        

        break;

    case 1002:

        [self.subView addSubview:oneView.view];

        [currentView removeFromSuperview];

        currentView = oneView.view;

        

        break;

    case 1003:

        [self.subView addSubview:twoView.view];

        [currentView removeFromSuperview];

        currentView = twoView.view;

        

        break;

        

    default:

        break;

}

}