When I push view controller its take time to navigate - ios

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

Related

kukushi/SideMenu Reveal Menu not working from presented anotherViewController

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)

Storyboard returns nil on main controller after login

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

How can we open the tab bar first VC on click in Swift

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)

Pass a type as variable

How do I go about passing a Type as a variable in Swift 4?
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MapViewController") as! MapViewController
I have something similar to the above in a horrible if statement I'd like to move to a function, but not sure how I pass 'MapViewController' (or whatever the controller is as a variable).
'"Pseduo" Code'
function setVC(withViewController : Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MapViewController") as! withViewController
}
You could use generic parameters like here:
function setVC<T>(withViewController: T) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MapViewController") as! T
}

How do I force a ViewController to present without the user pressing any buttons?

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)

Resources