Going to the rootViewController of another navigationController programmatically?
By : NBStudios
Date : March 29 2020, 07:55 AM
This might help you I have an iPhone app with a UITabBar, and each tab has a unique navigationController. , you can pop to root view controller as code :
[(UINavigationController *)self.tabBarController.selectedViewController popToRootViewControllerAnimated:YES];
|
Programmatically change rootViewController of storyBoard
By : Leonie Schonewille
Date : March 29 2020, 07:55 AM
I hope this helps you . I have created my project using Storyboards. The root ViewController lies inside a Storyboard, I have not written a single code in the appDelegate. , Objective-C: code :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarcontroller"];
[[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController];
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewControllerWithIdentifier("tabBarcontroller") as UITabBarController
UIApplication.sharedApplication().keyWindow?.rootViewController = viewController;
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewController(withIdentifier: "tabBarcontroller") as! UITabBarController
UIApplication.shared.keyWindow?.rootViewController = viewController
|
Create a TabBar programmatically but not on the rootViewController
By : Dhruva Upamanyu
Date : March 29 2020, 07:55 AM
I hope this helps you . Push to UITabBarController instead of CreateElement tableViewController, when didSelect of tableview called in Element TableViewController. From didSelectRowAt indexPath of Element TableViewController code :
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let tab = TabbarController()
self.navigationController?.pushViewController(tab, animated: true)
}
class TabbarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let createElement = CreateElementTVC() //Create Element TableViewController
createElement.tabBarItem = UITabBarItem(tabBarSystemItem: .history, tag: 0)
let more = MoreVC() //For eg. take empty UIViewController for another tab
more.tabBarItem = UITabBarItem(tabBarSystemItem: .more, tag: 1)
//Assign view controllers which you want to show in tab bar
self.viewControllers = [createElement, more].
}
}
|
How to programmatically come to rootViewController without using UINavigationController
By : user3055271
Date : December 21 2020, 03:04 PM
Hope this helps I'm using swift in iOS. I have to navigate back to my rootViewController from the current UIViewController by clicking on a button and I am not using UINavigationController. , Try this in your button action: code :
@IBAction func buttonClicked(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
|
how can i change programmatically the rootViewController using Storyboards?
By : Burt Walker
Date : March 29 2020, 07:55 AM
Any of those help You can set a cookie (using NSUserDefaults for example) telling you that you need to start from a different view controller. Then in you app delegate you can check for this cookie value and change the initial view controller of your storyboard like that
|