想讓 UITabBarController 啟動時直接停在指定的分頁,其實非常簡單——它本身就提供了一個 selectedIndex 屬性。
@property(nonatomic) NSUInteger selectedIndex; UITabBarController *VC = [[UITabBarController alloc]init]; VC.selectedIndex = n-1; [self.navigationController pushViewController:VC animated:YES];
只要把 selectedIndex 設為目標分頁的索引(注意索引從 0 開始,所以第 n 個要寫 n-1),該分頁就會成為預設選中並顯示的頁面。