2013-03-24 61 views
0

當我在Xcode中創建一個默認的Tab Bar應用程序時,我獲取了Storyboard,AppDelegate和兩個Controller的默認選項卡。我想要實現的是在重新啓動應用程序後保存上次打開的選項卡,例如我在第二個選項卡欄中執行某些操作,並且需要關閉應用程序。但是當我再次運行它時,它會自動在第二個選項卡中打開。我在「iOS 5 Developer's Cookbook」中看到,您需要爲此創建新方法(tabBarController:didEndCustomizingViewControllers:changed:),但我不知道放置位置的位置,因爲我只有AppDelegate,並且沒有整個UITabBarController的控制器, m試圖用Storyboard做到這一點。在StoryBoard中保存UITabBar設置

+0

從Apple觀看此視頻:WWDC 2012會議208:保存和恢復應用程序狀態。 – user523234 2013-03-24 11:23:41

+0

@ user523234非常感謝!我希望這部電影能夠解決我的問題! – cojoj 2013-03-24 11:31:06

+0

順便說一句:如果你只是想自動打開最後一個標籤,那麼Dipen的答案就足夠了。 – user523234 2013-03-24 11:46:11

回答

0
UITabBarController *tabbar = [[UITabBarController alloc] init]; 

// Set selected tab bar Number in UITabBarController Delegate Method 
// - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController; 
[[NSUserDefaults standardUserDefaults] setInteger:[tabbar selectedIndex] forKey:@"selectedIndex"]; 
[[NSUserDefaults standardUserDefaults] synchronize]; 


// Retrive the selectedIndex in Method 
// - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
NSInteger selectedIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedIndex"]; 
//Now set your selected Tabbar 
[tabbar setSelectedIndex:selectedIndex];