We are developing Quick Action (3D touch) implemented from iOS 9 and later.
I was able to call the specified ViewController (StoryBoard) from within Appdelegate, but
I don't know how to call TabBarController
How can I add TabBar created with StoryBoard to rootViewController?
-(void) application:(UIAapplication*) application
performActionForShortcutItem: (UIAapplicationShortcutItem*)shortcutItem
completionHandler:(void(^)(BOOL)) completionHandler {
if([shortcutItem.typecompare:@"Typecode" in info.plist] == NSOrderedSame) {
self.window=[UIWindow alloc] initWithFrame: UISscreen.mainScreen.bounds];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController* viewController;
viewController = [storyboard instantiateViewControllerWithIdentifier: @ "ViewControllerID Name";
self.window.rootViewController=viewController;
self.window makeKeyAndVisible;
}
}
Resolved
UIViewController*viewController;
viewController = [storyboard instantiateViewControllerWithIdentifier: @ "ViewControllerID Name";
self.window.rootViewController=viewController;
View assigned to Index=1 in UITab from to ↓ is now available
UITabBarController*tabBarController=[storyboard instantiateViewControllerWithIdentifier:@"tabBarControllerID Name";
tabBarController.selectedIndex=1;
self.window.rootViewController=tabBarController;
I will give you a supplementary answer."You can do this," "I think it's better to do this."
Consider using the -(UIViewController*) instantiateViewControllerWithIdentifier: (NSString*) instead of the
UIStoryboard
method -(UIViewController*) instantiateInitialViewController
The latter method instantiates and returns the base ViewController in the Storyboard."Basic" refers to the ViewController with the arrow in the figure below, and is checked for "Is Initial View Controller" in the Attributes Inspector.
UITabBarController*tabBarController=(UITabBarController*) [storyboard instantiateInitialViewController];
tabBarController.selectedIndex=1;
self.window.rootViewController=tabBarController;
Instancing according to the intent of editing the Storyboard means using this method.
© 2024 OneMinuteCode. All rights reserved.