开发者

How to jump to 2nd level viewController on startup in navigation based iPhone app

开发者 https://www.devze.com 2023-01-13 22:53 出处:网络
I have a navigation based iPhone app. Normally you start on the RootViewController, there you can select a row from an UITableView which brings you to another ViewController, let\'s call it SecondLeve

I have a navigation based iPhone app. Normally you start on the RootViewController, there you can select a row from an UITableView which brings you to another ViewController, let's call it SecondLevelViewController.

When the app is started I check if it was quit from SecondLevelViewController (via a parameter saved to the defaultUserSettings). If it was, I want to display that SecondLevelViewController again.

To achieve this I do the check in my application delegates

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

method, right after

[window addSubview:[navigationController view]];
[window makeKeyAndVisible];

Then I add the SecondLevelViewController to the view stack. I tried it with pushViewController and with setViewControllers:

        SecondLevelViewController *newVC = [[SecondLevelViewController alloc] initWithNibName:@"SecondLevelView" bundle:nil];            
        [self.navigationController setViewControllers:[NSArray arrayWithObjects:[self.navigationController.viewControllers objectAtIndex:0], newVC, nil]
                                             animated:YES];

The app then shows the desired view. Now the problem: the SecondLevelViewController displays a back button on the left side of the navigation bar. This button doesn't appear when using the way described above. My conclusion is, that the RootViewController isn't yet full开发者_StackOverflow社区y initialized at the time I go the the SecondLevelViewController. Is this possible? How can I avoid this?

Thanks, Mark.


Yes .......It's suppose to be true..... You can do the thing...like this..

Just check the condition as per your setting and it's directly coming from RootViewController then put a Custom Back Button/Bar Button in navigation bar.....of SecondLevelViewController.

Before this You need to check the condition... if it's true use use custom button

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Back:)];

  • (void) Back: (id) sender{

    [self.navigationController popToRootViewControllerAnimated:YES]; }

I think so it would definitely work for u.

0

精彩评论

暂无评论...
验证码 换一张
取 消