2011-03-16 55 views
1

当我点击TTTabBar时,选中的选项卡发送给我一个正确的ViewController,然后我点击另一个TTTabBar它会将我发送给另一个..... etc,但我该如何删除最后一个ViewController,所以它们不会一直堆叠在一起。删除未使用的ViewControllers

- (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){ 
+0

if([viewController isKindOfClass:[UIViewController class]]){ \t \t [viewController.view removeFromSuperview]; \t}其他{ \t \t \t} – Duny 2011-03-17 01:21:32

+0

谢谢,我添加了什么我得到了工作上面 – Duny 2011-03-17 01:24:02

回答

0

TTNavigator你写了一个类?它看起来像一个单身经理类... viewControllerForUrl是否返回一个自动发布的实例UIViewController?您可以在TTNavigator中实现一个堆栈,您可以在其中持有对所有视图控制器的引用,然后按照您认为合适的方式弹出它们。

+0

没有TTNavigator是Three20框架的一部分。 – Duny 2011-03-17 00:50:40