I am setting a new navigation for my app on launch. But when I launch it appears from a black color animation.After black color it sets it navigation bar. Please tell me what is issue.
I am using below code
var controller = UIViewController() //App Theming var navController = UINavigationController() navController.navigationBar.barTintColor = UIColor.white navController.navigationBar.tintColor = UIColor.white navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] navController.navigationBar.shadowImage = UIImage() navController.navigationBar.setBackgroundImage(UIImage(), for: .default) navController.navigationBar.isTranslucent = false navController = UINavigationController(rootViewController: viewcontroller) navController.navigationBar.isHidden = true let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.window?.rootViewController = navController appDelegate.window?.makeKeyAndVisible()
4 Answers
Answers 1
The problem is this line:
navController.navigationBar.isHidden = true
Delete it and try again.
Answers 2
Please use snippet bellow
In this I am using ViewController from Main storyboard
// mainStoryboard let mainStoryboard = UIStoryboard(name: "Main", bundle: nil) // rootViewController let rootViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController // navigationController let navigationController = UINavigationController(rootViewController: rootViewController!) //App Theming navigationController.navigationBar.barTintColor = UIColor.white navigationController.navigationBar.tintColor = UIColor.white navigationController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] navigationController.title = "Testing Th" navigationController.navigationBar.shadowImage = UIImage() navigationController.navigationBar.setBackgroundImage(UIImage(), for: .default) navigationController.navigationBar.isTranslucent = false navigationController.navigationBar.isHidden = true // self.window self.window = UIWindow(frame: UIScreen.main.bounds) self.window!.rootViewController = navigationController self.window!.makeKeyAndVisible()
If I unhide NavigationBar
navigationController.navigationBar.isHidden = false
Answers 3
- I can see that you did not give the navigationController any viewControllers.
You need to pass the navigation controller at least one viewController for it to know which viewController to start your navigation process from, follow the code below:
var window: UIWindow? let nav = UINavigationController()
1- here is where i declared my Initial viewController (where i want my navigation process to start from)
var main = HomeViewController(nibName: "HomeViewController", bundle: nil)
2- here is where i give the navigationController the first viewController to start from.
window?.rootViewController = nav nav.viewControllers = [main]//you need to have this line nav.isNavigationBarHidden = true window?.makeKeyAndVisible()
Answers 4
alright i just noticed you're using storyboards, give this a try:
var storyboard = UIStoryboard(name: "Main", bundle: nil) var ivc = storyboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController navigationController?.pushViewController(anIvc, animated: true) window.rootViewController = ivc window.rootViewController = navigationController window.makeKeyAndVisible()
0 comments:
Post a Comment