If you wanna remove the class self in the current view, and it had have IBOutlets connect with the removed view that you did need to setup the IBOutlets to nil, it still works for me, like this :
-(void)backRootController{
//I wanna change the current viewController to rootViewController on self.tabBarController.
RootViewController *_rootViewController = [[RootViewController alloc] init];
NSArray *_viewControllers = self.tabBarController.viewControllers;
NSMutableArray *_tabs = [NSMutableArray array];
for( UIViewController *_tabViewController in _viewControllers ){
if( _tabViewController == self ){
_rootViewController.tabBarItem = _tabViewController.tabBarItem;
_tabViewController = _rootViewController;
}
[_tabs addObject:_tabViewController];
}
self.tabBarController.viewControllers = [NSArray arrayWithArray:_tabs];
//To setup the IBOutlets to nil to avoid [CALayer release] crash. ( UILabel, UIView, UIImageView )
self.outPreviewLabel = nil;
self.outPreviewView = nil;
self.outPreviewImageView.image = nil;
self.outPreviewImageView = nil;
//Then remove the view and exchanged current controller.
[self.view removeFromSuperview];
[self removeFromParentViewController];
[_rootViewController release];
}