drc drc - 3 months ago 31
iOS Question

Set rootViewController of UINavigationController by method other than initWithRootViewController

How Do I set the

rootViewController
of
UINavigationController
by a method other than
initWithRootViewController
?

I want use
initWithNavigationBarClass:toolbarClass:
to deliver a custom toolbar for my NavigationController, so I don't think I can use
initWithRootViewController
.

Answer

You can solve this by calling setViewControllers.

Like this:

UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];

[navigationController setViewControllers:@[yourRootViewController] animated:NO];