1

I'm developing an iOS 5 app using Storyboard.

I have UITabBarController which has 3 tabs. Every tab has its own UINavigationController. UINavigationController of first tab has one UITableViewController which segues to another UIViewController etc. UINavigationController of second tab has only one UIViewController.

What I want to achieve is to navigate to UIViewController (second view in UINavigationController of first tab) when certain action happens in UIViewController of second tab.

I've tried to accomplish this using push segue but then the navigation stack becomes mixed with view controllers of different tabs (the back button in destination view controller points to view controller of another tab).

So I want to know what is the "correct way" to accomplish this kind of transition between view controllers of different tabs.

Any help would be very appreciated.

4

1 に答える 1

0

最初のタブの最初のviewControllerがロードされていない可能性があるため、通知を使用することはできません。

したがって、1つの方法は、設定(nsuserdefaultsなど)を保存してから、タブを最初のタブに切り替え、最初のタブの最初のviewControllerで、viewDidAppearまたはviewWillAppearでこの設定を確認し、設定されている場合は設定をリセットすることです。 (次回)、2番目のviewControllerに自動ナビゲート(プッシュ)します。

BOOL shouldAutoPush=YES;
[[NSUserDefaults standardUserDefaults] shouldAutoPush forKey:@"shouldAutoPush"];
[[NSUserDefaults standardUserDefaults] synchronize]; 
[self.tabBarController setSelectedIndex:0];

-(void)viewWillAppear:(BOOL)animated {
     if ( [[NSUserDefaults standardUserDefaults] objectForKey:@"shouldAutoPush"] ) {
        BOOL shouldAutoPush=NO;
        [[NSUserDefaults standardUserDefaults] shouldAutoPush forKey:@"shouldAutoPush"];
        [[NSUserDefaults standardUserDefaults] synchronize]; 
        [self.navigationController pushViewController:secondViewController animated:YES];                
     }
}
于 2012-09-24T08:15:21.530 に答える