2

我正在申請一個嵌入在UITabBarController內的UINavigationController的應用程序。 UINavigationController有一個UITableView,當一個單元被點擊時,它轉換爲一個細節控制器當UITabBar選項卡更改時關閉DetailController?

我的問題是:我選擇在[TAB1],並過渡到DetailController細胞。如果我選擇[TAB2],然後返回到[TAB1],它仍在細節控制器上。是否有[TAB2]被選中,我可以展開/關閉詳細控制器[TAB1](即如此它再次顯示錶格視圖單元格)。

我的想法的另一條線是,這樣做不會離開UI的狀態下用戶離開它,即觀看DetailController並按[TAB2]返回[TAB1]將提出後,用戶在UITableView中的單元格。這種感覺對於應用程序,如果你離開TAB,這就是爲什麼我要求恢復的DetailController更好...

NB:I present the *DetailController* via a push segue from the的UITableViewCell .

回答

2

您可以實現UITabBarControlleDelegate並返回UINavigationController的根視圖使用popToRootViewControllerAnimated:當選項卡更改時。

代碼示例:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
    tabBarController.delegate = self; 
    return YES; 
} 

    - (BOOL)tabBarController:(UITabBarController *)tabBarController 
shouldSelectViewController:(UIViewController *)viewController 
{ 
    UIViewController *currentController = tabBarController.selectedViewController; 
    if ([currentController isKindOfClass:[UINavigationController class]]) 
     [(UINavigationController *)currentController popToRootViewControllerAnimated:NO]; 
    return YES; 
} 
+0

爲了實現這一點,你會做的UINavigationController的UITabBarControllerDelegate爲的UITabBarController。我是否正確理解這一點? – fuzzygoat 2013-03-22 19:09:00

+0

不,您可以將'UIAppDelegate'設置爲'UITabBarControllerDelegate'的委託 – 2013-03-22 19:11:16

+1

非常感謝Sergey,非常感謝您擴展您的答案,現在我明白了。 – fuzzygoat 2013-03-22 21:45:07

相關問題