删除未使用的ViewControllers

时间:2011-03-16 19:57:43

标签: iphone objective-c three20

当我点击TTTabBar时,选中的选项卡会将我发送给一个正确的ViewController,然后我点击另一个TTTabBar它会将我发送给另一个......等等,但是如何删除最后一个ViewController ,所以他们不要只是堆叠在一起。

- (void)tabBar:(TTTabBar*)tabBar tabSelected:(NSInteger)selectedIndex
{       
if(selectedIndex == 0){
    UIViewController* viewController = (UIViewController*)[[TTNavigator navigator] viewControllerForURL:@"tt://Forum"];
    [self.view addSubview:viewController.view];
    [self.view addSubview:_tabBar];
}else if(selectedIndex == 1) {
    UIViewController* viewController = (UIViewController*)[[TTNavigator navigator] viewControllerForURL:@"tt://Profile"];
    [self.view addSubview:viewController.view];
    [self.view addSubview:_tabBar];
}else if(selectedIndex == 2) {
    UIViewController* viewController = (UIViewController*)[[TTNavigator navigator] viewControllerForURL:@"tt://PMs"];
    [self.view addSubview:viewController.view];
    [self.view addSubview:_tabBar];
}else if(selectedIndex == 3) {
    UIViewController* viewController = (UIViewController*)[[TTNavigator navigator] viewControllerForURL:@"tt://Friends"];
    [self.view addSubview:viewController.view];
    [self.view addSubview:_tabBar];
} 
} 

我让这个工作

if ([viewController isKindOfClass:[UIViewController class]]) {
    [viewController.view removeFromSuperview];
} else {

}

当我在上面添加

    if(selectedIndex == 0){

2 个答案:

答案 0 :(得分:1)

使用:

- (void)removeFromSuperview

要在您的场景中执行此操作,您必须保持对当前视图的引用,或者创建一种使用标记获取对它的引用的方法。

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

答案 1 :(得分:0)

TTNavigator是你写的一堂课吗?对我来说,它看起来像一个单例管理器类... viewControllerForUrl是否返回UIViewController的自动释放实例?您可以在TTNavigator中实现一个堆栈,您可以在其中保存对所有视图控制器的引用,然后根据需要弹出它们。

相关问题