2011-03-16 80 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