I use side menu library "kukushi/SideMenu"
I send data to another tableViewController (ScheduleTableVC)
let navigation = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SchedulePage") as! UINavigationController
let vc = navigation.viewControllers.first as! ScheduleTableVC
vc.text = ""
self.present(navigation, animated: true, completion: nil)
But in ScheduleTableVC library function
self.sideMenuController?.revealMenu()
not working, which must show menu
Solve it with this
let navigation = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SchedulePage") as! UINavigationController
let vc = navigation.viewControllers.first as! ScheduleTableVC
vc.text = ""
sideMenuController?.setContentViewController(to: navigation, animated: false, completion: nil)
Related
I am using a single Storyboard named as Main and when I am trying to redirect(push) from login screen to Home screen, On Home screen in ViewDidLoad I am getting self.storyboard is nil so UI is distorting(view, Buttons, labels are changing its position). I am getting this problem too frequent but not every-time.
Can anyone please help me out, it would be appreciated.
Try this
let startViewController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "StartViewController") as? StartViewController
self.navigationController?.pushViewController(startViewController!, animated: true)
let sb = UIStoryboard(name: "Main", bundle: nil)
let moveController = sb.instantiateViewController(withIdentifier: "StartViewController ") as! StartViewController
self.navigationController?.pushViewController(moveController, animated: true)
Please try below code
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if storyboard != nil{
let VC = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
self.navigationController?.pushViewController(VC, animated: true)
}
Hope you will get your solution if don't than tell me
i have a VC which on click of button want to open the tabbar VC that is on the first index. I wana open this through present style. My home vc is on the tab bar first index. How can i open that?. My UI looks like that,
The code i tried is this,
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "MainVC") as! MainVC
if let vcs = tabbarVC.viewControllers,
let nc = vcs.first as? UINavigationController,
self.present(tabbarVC, animated: false, completion: nil)
you can give an id and open directly
let first = storyboard.instantiateViewController(withIdentifier: "firstID")
self.present(first , animated: false, completion: nil)
//
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "MainVC") as! MainVC
self.present(tabbarVC, animated: false, completion: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "AbcViewController") as! AbcViewController
self.navigationController?.pushViewController(vc, animated: true)
I will happy to help you
Please try this code:
DispatchQueue.main.async(execute: {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "AbcViewController") as! AbcViewController
self.navigationController?.pushViewController(vc, animated: true)
})
Thank You
Yash Shekhada
When a function is called, I would like SixthViewController to be presented to the user without the user needing to press any buttons. I know how to present another ViewControllerby setting a button to "Show" another ViewController, but how can I programmatically force SixthViewController to present itself once the function is called?
you can present viewcontroller with this way:
let destVC = SixthViewController()
self.present(destVC, animated: true, completion: nil)
or
let storyboard: UIStoryboard = UIStoryboard(name: "storyboardNamehere", bundle: nil)
let destVC = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerIdentifierhere" as! SixthViewController
self.present(destVC, animated: true, completion: nil)
========================================================================
just write down this function and also called it when u want to push or write down it in any function like func pushViewController and called it self.pushViewController() that's it bro.
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let sixthViewController = storyBoard.instantiateViewController(withIdentifier: "SixthViewController") as! SixthViewController
self.navigationController?.pushViewController(sixthViewController, animated: true)
If you are not using segues but navigation controller try this:
let destinationVC = SixthViewController()
self.navigationController?.pushViewController(destinationVC, animated: true)
If you just want to show it without navigation controller:
let destinationVC = SixthViewController()
self.present(destinationVC, animated: true, completion: nil)
If you are using storyboard:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let destVC = self.storyboard?.instantiateViewController(withIdentifier: "SixthViewController" as! SixthViewController
self.present(destVC, animated: true, completion: nil)
In the scenario where you have a viewController which you want to present as root view above everything else what is the right way to do this?
let Storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let MY_VIEW = Storyboard.instantiateViewControllerWithIdentifier("VIEWID")
//Is this the right way?
UIApplication.sharedApplication().delegate.window?.rootViewController?.presentViewController(MY_VIEW, animated: true, completion: nil)
//Or this?
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(MY_VIEW, animated: true, completion: nil)
In other words why would you use UIApplication.sharedApplication().delegate.window? over UIApplication.sharedApplication().keyWindow?.rootViewController? and in what scenarios? What would be the pros/cons of using one or the other?
You can do as follow.
let rootController = storyboard.instantiateViewControllerWithIdentifier("VIEWID") as! SplashVC
if self.window != nil {
self.window!.rootViewController = rootController
}
advantage of this is not getting crash when window is nil.
Another way is that(Most secure way i think)
let navigationController:UINavigationController = storyboard.instantiateInitialViewController() as! UINavigationController
let rootViewController:UIViewController = storyboard.instantiateViewControllerWithIdentifier("VIEWID") as! LoginVC
navigationController.viewControllers = [rootViewController]
self.window?.rootViewController = navigationController
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController: MainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController
let rootViewController = self.window!.rootViewController as! UINavigationController
rootViewController.pushViewController(viewController, animated: true)