I have created my project using Storyboards
. The root ViewController
lies inside a Storyboard
, I have not written a single code in the appDelegate
.
Now I want to show a tour of my app, so I want to change the root ViewController
from Tab Bar
to my TourVC and when the tour of the app is finished , I want to again switch back my root ViewController
to Tab Bar
.
So I looked up online and followed the following points
1) Remove Storyboards
from app.plist file,
2) Uncheck option "isInitialViewController" from Storyboards
which is checked in case of Tab Bar
controller because its a root ViewController
,
3) Add this code in appDelegate.m file.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ProductTourViewController *PT = [[ProductTourViewController alloc] initWithNibName:@"ProductTourViewController" bundle:nil];
self.window.rootViewController = PT;
[self.window makeKeyAndVisible];
return YES;
But my app crashes with this error log,
[ProductTourViewController selectedViewController]: unrecognized selector sent to instance 0x1766a9e0
And also I get a warning,
Unsupported Configuration: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.
Objective-C:
Swift :
Swift 3:
Use below in didFinishLaunchingWithOptions Appdelegate function. Replace "HomeViewController" with ViewController you want to set as Root ViewController on app launch.
This is an old article, but I will reply. I do not recommend the following code.
Because you are creating two instances. I recommend writing the following code in the appropriate ViewController.
In swift we can implement it is as following
I use simple this: