Changing Root view controllers gives IBOutlet as nil










0














I have to change my root view controller according to login status.



I had change my AppDelegate file and create a MainNavigationController class which extends UINavigationController.



**PROBLEM :- **
When the defined root class is loaded it gives all outlet variables as nil.



CODE



 class PostalViewController: UIViewController {

@IBOutlet weak var btn_currentLocation: UIButton!
@IBOutlet weak var btn_viewAccount: UIButton!
@IBOutlet weak var in_postCode: UITextField!

let locManager = CLLocationManager()

override func viewDidLoad()
super.viewDidLoad()

// Here it gives a nil on btn_currentLocation

btn_currentLocation.layer.cornerRadius = 15.0
btn_currentLocation.layer.masksToBounds = true

btn_currentLocation.setButtonGradient(colorOne: UIColor(named: "lightBlue")!, colorTwo: UIColor(named: "gradient2")!)

btn_viewAccount.layer.cornerRadius = 15.0
btn_viewAccount.layer.masksToBounds = true

// Add search button in post code text field
let searchButton = UIButton(type: .custom)
searchButton.setImage(UIImage(named: "iconSearch"), for: .normal)
searchButton.frame = CGRect(x: CGFloat(in_postCode.frame.size.width - 25), y: CGFloat(5), width: CGFloat(25), height: CGFloat(25))
searchButton.addTarget(self, action: #selector(self.actionSearch), for: .touchUpInside)
in_postCode.rightView = searchButton
in_postCode.rightViewMode = .always




AppDelegate.swift (only that particular function)



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
// Override point for customization after application launch.

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()
return true



MainNavigationController.swift



class MainNavigationController : UINavigationController

var isLogin : Bool?

override func viewDidLoad()
super.viewDidLoad()
view.backgroundColor = .white

isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if (isLogin != nil && isLogin!)

perform(#selector(postalController), with: nil, afterDelay: 0.01)

else

perform(#selector(showHomeContoller), with: nil, afterDelay: 0.01)




@objc func showHomeContoller ()

let homepageController = HomePageViewController()
present(homepageController, animated: true, completion: nil)


@objc func postalController ()

let postalController = PostalViewController()
viewControllers = [postalController]




EDIT



I have add a screenshot below, I have to switch my root view between HomePage and Postal



enter image description here










share|improve this question























  • Are you using storyboard?
    – Robert Dresler
    Nov 12 at 15:30










  • @RobertDresler Yes. Iam using storyboard
    – Nikhil Sawant
    Nov 12 at 15:31











  • Ok, check my answer
    – Robert Dresler
    Nov 12 at 15:38










  • Can you add photo of your storyboard?
    – Robert Dresler
    Nov 12 at 15:44










  • @RobertDresler Yeah sure.
    – Nikhil Sawant
    Nov 12 at 16:05















0














I have to change my root view controller according to login status.



I had change my AppDelegate file and create a MainNavigationController class which extends UINavigationController.



**PROBLEM :- **
When the defined root class is loaded it gives all outlet variables as nil.



CODE



 class PostalViewController: UIViewController {

@IBOutlet weak var btn_currentLocation: UIButton!
@IBOutlet weak var btn_viewAccount: UIButton!
@IBOutlet weak var in_postCode: UITextField!

let locManager = CLLocationManager()

override func viewDidLoad()
super.viewDidLoad()

// Here it gives a nil on btn_currentLocation

btn_currentLocation.layer.cornerRadius = 15.0
btn_currentLocation.layer.masksToBounds = true

btn_currentLocation.setButtonGradient(colorOne: UIColor(named: "lightBlue")!, colorTwo: UIColor(named: "gradient2")!)

btn_viewAccount.layer.cornerRadius = 15.0
btn_viewAccount.layer.masksToBounds = true

// Add search button in post code text field
let searchButton = UIButton(type: .custom)
searchButton.setImage(UIImage(named: "iconSearch"), for: .normal)
searchButton.frame = CGRect(x: CGFloat(in_postCode.frame.size.width - 25), y: CGFloat(5), width: CGFloat(25), height: CGFloat(25))
searchButton.addTarget(self, action: #selector(self.actionSearch), for: .touchUpInside)
in_postCode.rightView = searchButton
in_postCode.rightViewMode = .always




AppDelegate.swift (only that particular function)



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
// Override point for customization after application launch.

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()
return true



MainNavigationController.swift



class MainNavigationController : UINavigationController

var isLogin : Bool?

override func viewDidLoad()
super.viewDidLoad()
view.backgroundColor = .white

isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if (isLogin != nil && isLogin!)

perform(#selector(postalController), with: nil, afterDelay: 0.01)

else

perform(#selector(showHomeContoller), with: nil, afterDelay: 0.01)




@objc func showHomeContoller ()

let homepageController = HomePageViewController()
present(homepageController, animated: true, completion: nil)


@objc func postalController ()

let postalController = PostalViewController()
viewControllers = [postalController]




EDIT



I have add a screenshot below, I have to switch my root view between HomePage and Postal



enter image description here










share|improve this question























  • Are you using storyboard?
    – Robert Dresler
    Nov 12 at 15:30










  • @RobertDresler Yes. Iam using storyboard
    – Nikhil Sawant
    Nov 12 at 15:31











  • Ok, check my answer
    – Robert Dresler
    Nov 12 at 15:38










  • Can you add photo of your storyboard?
    – Robert Dresler
    Nov 12 at 15:44










  • @RobertDresler Yeah sure.
    – Nikhil Sawant
    Nov 12 at 16:05













0












0








0


1





I have to change my root view controller according to login status.



I had change my AppDelegate file and create a MainNavigationController class which extends UINavigationController.



**PROBLEM :- **
When the defined root class is loaded it gives all outlet variables as nil.



CODE



 class PostalViewController: UIViewController {

@IBOutlet weak var btn_currentLocation: UIButton!
@IBOutlet weak var btn_viewAccount: UIButton!
@IBOutlet weak var in_postCode: UITextField!

let locManager = CLLocationManager()

override func viewDidLoad()
super.viewDidLoad()

// Here it gives a nil on btn_currentLocation

btn_currentLocation.layer.cornerRadius = 15.0
btn_currentLocation.layer.masksToBounds = true

btn_currentLocation.setButtonGradient(colorOne: UIColor(named: "lightBlue")!, colorTwo: UIColor(named: "gradient2")!)

btn_viewAccount.layer.cornerRadius = 15.0
btn_viewAccount.layer.masksToBounds = true

// Add search button in post code text field
let searchButton = UIButton(type: .custom)
searchButton.setImage(UIImage(named: "iconSearch"), for: .normal)
searchButton.frame = CGRect(x: CGFloat(in_postCode.frame.size.width - 25), y: CGFloat(5), width: CGFloat(25), height: CGFloat(25))
searchButton.addTarget(self, action: #selector(self.actionSearch), for: .touchUpInside)
in_postCode.rightView = searchButton
in_postCode.rightViewMode = .always




AppDelegate.swift (only that particular function)



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
// Override point for customization after application launch.

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()
return true



MainNavigationController.swift



class MainNavigationController : UINavigationController

var isLogin : Bool?

override func viewDidLoad()
super.viewDidLoad()
view.backgroundColor = .white

isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if (isLogin != nil && isLogin!)

perform(#selector(postalController), with: nil, afterDelay: 0.01)

else

perform(#selector(showHomeContoller), with: nil, afterDelay: 0.01)




@objc func showHomeContoller ()

let homepageController = HomePageViewController()
present(homepageController, animated: true, completion: nil)


@objc func postalController ()

let postalController = PostalViewController()
viewControllers = [postalController]




EDIT



I have add a screenshot below, I have to switch my root view between HomePage and Postal



enter image description here










share|improve this question















I have to change my root view controller according to login status.



I had change my AppDelegate file and create a MainNavigationController class which extends UINavigationController.



**PROBLEM :- **
When the defined root class is loaded it gives all outlet variables as nil.



CODE



 class PostalViewController: UIViewController {

@IBOutlet weak var btn_currentLocation: UIButton!
@IBOutlet weak var btn_viewAccount: UIButton!
@IBOutlet weak var in_postCode: UITextField!

let locManager = CLLocationManager()

override func viewDidLoad()
super.viewDidLoad()

// Here it gives a nil on btn_currentLocation

btn_currentLocation.layer.cornerRadius = 15.0
btn_currentLocation.layer.masksToBounds = true

btn_currentLocation.setButtonGradient(colorOne: UIColor(named: "lightBlue")!, colorTwo: UIColor(named: "gradient2")!)

btn_viewAccount.layer.cornerRadius = 15.0
btn_viewAccount.layer.masksToBounds = true

// Add search button in post code text field
let searchButton = UIButton(type: .custom)
searchButton.setImage(UIImage(named: "iconSearch"), for: .normal)
searchButton.frame = CGRect(x: CGFloat(in_postCode.frame.size.width - 25), y: CGFloat(5), width: CGFloat(25), height: CGFloat(25))
searchButton.addTarget(self, action: #selector(self.actionSearch), for: .touchUpInside)
in_postCode.rightView = searchButton
in_postCode.rightViewMode = .always




AppDelegate.swift (only that particular function)



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
// Override point for customization after application launch.

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()
return true



MainNavigationController.swift



class MainNavigationController : UINavigationController

var isLogin : Bool?

override func viewDidLoad()
super.viewDidLoad()
view.backgroundColor = .white

isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if (isLogin != nil && isLogin!)

perform(#selector(postalController), with: nil, afterDelay: 0.01)

else

perform(#selector(showHomeContoller), with: nil, afterDelay: 0.01)




@objc func showHomeContoller ()

let homepageController = HomePageViewController()
present(homepageController, animated: true, completion: nil)


@objc func postalController ()

let postalController = PostalViewController()
viewControllers = [postalController]




EDIT



I have add a screenshot below, I have to switch my root view between HomePage and Postal



enter image description here







ios swift uiviewcontroller uikit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 16:07

























asked Nov 12 at 15:14









Nikhil Sawant

6110




6110











  • Are you using storyboard?
    – Robert Dresler
    Nov 12 at 15:30










  • @RobertDresler Yes. Iam using storyboard
    – Nikhil Sawant
    Nov 12 at 15:31











  • Ok, check my answer
    – Robert Dresler
    Nov 12 at 15:38










  • Can you add photo of your storyboard?
    – Robert Dresler
    Nov 12 at 15:44










  • @RobertDresler Yeah sure.
    – Nikhil Sawant
    Nov 12 at 16:05
















  • Are you using storyboard?
    – Robert Dresler
    Nov 12 at 15:30










  • @RobertDresler Yes. Iam using storyboard
    – Nikhil Sawant
    Nov 12 at 15:31











  • Ok, check my answer
    – Robert Dresler
    Nov 12 at 15:38










  • Can you add photo of your storyboard?
    – Robert Dresler
    Nov 12 at 15:44










  • @RobertDresler Yeah sure.
    – Nikhil Sawant
    Nov 12 at 16:05















Are you using storyboard?
– Robert Dresler
Nov 12 at 15:30




Are you using storyboard?
– Robert Dresler
Nov 12 at 15:30












@RobertDresler Yes. Iam using storyboard
– Nikhil Sawant
Nov 12 at 15:31





@RobertDresler Yes. Iam using storyboard
– Nikhil Sawant
Nov 12 at 15:31













Ok, check my answer
– Robert Dresler
Nov 12 at 15:38




Ok, check my answer
– Robert Dresler
Nov 12 at 15:38












Can you add photo of your storyboard?
– Robert Dresler
Nov 12 at 15:44




Can you add photo of your storyboard?
– Robert Dresler
Nov 12 at 15:44












@RobertDresler Yeah sure.
– Nikhil Sawant
Nov 12 at 16:05




@RobertDresler Yeah sure.
– Nikhil Sawant
Nov 12 at 16:05












2 Answers
2






active

oldest

votes


















1














I suppose you just want to show PostalViewController if user is logged. If user isn't logged you want to show just HomePageViewController. First delete these lines from app delegate, you don't need this:



window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()


Now delete the whole navigation controller class. You won't need it because you will do all of this in HomePageViewController. Now in HomePageViewController swift file add this to viewDidLoad()



isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if isLogin != nil
performSegue(withIdentifier: "segueToPostal", sender: self)



In the end set segue from HomePageViewController to PostalViewController



enter image description hereenter image description here



and set its identifier as segueToPostal



enter image description here



If you don't want to let user navigate back from Postal view controller you can just embbed PostalViewController in new NavigationController. Then just set segue from HomePageViewController to this NavigationController and set identifier.






share|improve this answer






















  • Yes, I have the tried the same, still not working, it gives the same runtime error
    – Nikhil Sawant
    Nov 12 at 15:38










  • @NikhilSawant try to follow these edited steps
    – Robert Dresler
    Nov 12 at 16:27










  • Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
    – Nikhil Sawant
    Nov 12 at 16:33










  • @NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
    – Robert Dresler
    Nov 12 at 16:37










  • yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
    – Nikhil Sawant
    Nov 12 at 16:39


















1














IBOulet is set when view controller is initialized with nib file.
So you need create the view controllers using the init method below



init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)


For example, if name of your xib file where you config your IBOultets the same as controllers name, you can just do next:



let postalController = PostalViewController(nibName: "PostalViewController", bundle: nil) 


Here You will have controller with initialized IBOutlets.



For using story board you should init them from story board.
Try to ini controllers next way:



let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) 
let vc = sb.instantiateViewController(withIdentifier: "PostalViewController")


And you should set storyboard id in your story board for the controller, like on the screen below.



storyboard id



Also you can find more info how to init correctly view controllers from storyboard here



What is a StoryBoard ID and how can i use this?






share|improve this answer






















  • Thanks for your response, but still the same results. i have replace in MainNavigationController
    – Nikhil Sawant
    Nov 12 at 15:50










  • Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
    – Gkolunia
    Nov 12 at 15:57











  • let me try it. Thanks
    – Nikhil Sawant
    Nov 12 at 16:05










  • yes i have set the storyboard ID
    – Nikhil Sawant
    Nov 12 at 16:10










  • please, check out my edited post, i've added more information.
    – Gkolunia
    Nov 12 at 16:11










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265050%2fchanging-root-view-controllers-gives-iboutlet-as-nil%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I suppose you just want to show PostalViewController if user is logged. If user isn't logged you want to show just HomePageViewController. First delete these lines from app delegate, you don't need this:



window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()


Now delete the whole navigation controller class. You won't need it because you will do all of this in HomePageViewController. Now in HomePageViewController swift file add this to viewDidLoad()



isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if isLogin != nil
performSegue(withIdentifier: "segueToPostal", sender: self)



In the end set segue from HomePageViewController to PostalViewController



enter image description hereenter image description here



and set its identifier as segueToPostal



enter image description here



If you don't want to let user navigate back from Postal view controller you can just embbed PostalViewController in new NavigationController. Then just set segue from HomePageViewController to this NavigationController and set identifier.






share|improve this answer






















  • Yes, I have the tried the same, still not working, it gives the same runtime error
    – Nikhil Sawant
    Nov 12 at 15:38










  • @NikhilSawant try to follow these edited steps
    – Robert Dresler
    Nov 12 at 16:27










  • Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
    – Nikhil Sawant
    Nov 12 at 16:33










  • @NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
    – Robert Dresler
    Nov 12 at 16:37










  • yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
    – Nikhil Sawant
    Nov 12 at 16:39















1














I suppose you just want to show PostalViewController if user is logged. If user isn't logged you want to show just HomePageViewController. First delete these lines from app delegate, you don't need this:



window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()


Now delete the whole navigation controller class. You won't need it because you will do all of this in HomePageViewController. Now in HomePageViewController swift file add this to viewDidLoad()



isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if isLogin != nil
performSegue(withIdentifier: "segueToPostal", sender: self)



In the end set segue from HomePageViewController to PostalViewController



enter image description hereenter image description here



and set its identifier as segueToPostal



enter image description here



If you don't want to let user navigate back from Postal view controller you can just embbed PostalViewController in new NavigationController. Then just set segue from HomePageViewController to this NavigationController and set identifier.






share|improve this answer






















  • Yes, I have the tried the same, still not working, it gives the same runtime error
    – Nikhil Sawant
    Nov 12 at 15:38










  • @NikhilSawant try to follow these edited steps
    – Robert Dresler
    Nov 12 at 16:27










  • Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
    – Nikhil Sawant
    Nov 12 at 16:33










  • @NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
    – Robert Dresler
    Nov 12 at 16:37










  • yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
    – Nikhil Sawant
    Nov 12 at 16:39













1












1








1






I suppose you just want to show PostalViewController if user is logged. If user isn't logged you want to show just HomePageViewController. First delete these lines from app delegate, you don't need this:



window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()


Now delete the whole navigation controller class. You won't need it because you will do all of this in HomePageViewController. Now in HomePageViewController swift file add this to viewDidLoad()



isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if isLogin != nil
performSegue(withIdentifier: "segueToPostal", sender: self)



In the end set segue from HomePageViewController to PostalViewController



enter image description hereenter image description here



and set its identifier as segueToPostal



enter image description here



If you don't want to let user navigate back from Postal view controller you can just embbed PostalViewController in new NavigationController. Then just set segue from HomePageViewController to this NavigationController and set identifier.






share|improve this answer














I suppose you just want to show PostalViewController if user is logged. If user isn't logged you want to show just HomePageViewController. First delete these lines from app delegate, you don't need this:



window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = MainNavigationController()


Now delete the whole navigation controller class. You won't need it because you will do all of this in HomePageViewController. Now in HomePageViewController swift file add this to viewDidLoad()



isLogin = UserDefaults.standard.bool(forKey: "isLogin")
print("IsLogin --->", isLogin!)

if isLogin != nil
performSegue(withIdentifier: "segueToPostal", sender: self)



In the end set segue from HomePageViewController to PostalViewController



enter image description hereenter image description here



and set its identifier as segueToPostal



enter image description here



If you don't want to let user navigate back from Postal view controller you can just embbed PostalViewController in new NavigationController. Then just set segue from HomePageViewController to this NavigationController and set identifier.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 17:06

























answered Nov 12 at 15:32









Robert Dresler

4,0251526




4,0251526











  • Yes, I have the tried the same, still not working, it gives the same runtime error
    – Nikhil Sawant
    Nov 12 at 15:38










  • @NikhilSawant try to follow these edited steps
    – Robert Dresler
    Nov 12 at 16:27










  • Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
    – Nikhil Sawant
    Nov 12 at 16:33










  • @NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
    – Robert Dresler
    Nov 12 at 16:37










  • yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
    – Nikhil Sawant
    Nov 12 at 16:39
















  • Yes, I have the tried the same, still not working, it gives the same runtime error
    – Nikhil Sawant
    Nov 12 at 15:38










  • @NikhilSawant try to follow these edited steps
    – Robert Dresler
    Nov 12 at 16:27










  • Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
    – Nikhil Sawant
    Nov 12 at 16:33










  • @NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
    – Robert Dresler
    Nov 12 at 16:37










  • yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
    – Nikhil Sawant
    Nov 12 at 16:39















Yes, I have the tried the same, still not working, it gives the same runtime error
– Nikhil Sawant
Nov 12 at 15:38




Yes, I have the tried the same, still not working, it gives the same runtime error
– Nikhil Sawant
Nov 12 at 15:38












@NikhilSawant try to follow these edited steps
– Robert Dresler
Nov 12 at 16:27




@NikhilSawant try to follow these edited steps
– Robert Dresler
Nov 12 at 16:27












Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
– Nikhil Sawant
Nov 12 at 16:33




Thanks for effort, intially i have implemented this, but here the problem is on Postal screen it gives me the back button of Homepage. And if i perform segue as present, then further back navigation is not showing.
– Nikhil Sawant
Nov 12 at 16:33












@NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
– Robert Dresler
Nov 12 at 16:37




@NikhilSawant Don't perform segue as present, try what I wrote: performSegue(withIdentifier: "segueToPostal", sender: self) and set segue how I described
– Robert Dresler
Nov 12 at 16:37












yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
– Nikhil Sawant
Nov 12 at 16:39




yes i have tried the same way you mentioned. Problem is on Postal screen it's giving a back button to HomePage again, which i don't want to.
– Nikhil Sawant
Nov 12 at 16:39













1














IBOulet is set when view controller is initialized with nib file.
So you need create the view controllers using the init method below



init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)


For example, if name of your xib file where you config your IBOultets the same as controllers name, you can just do next:



let postalController = PostalViewController(nibName: "PostalViewController", bundle: nil) 


Here You will have controller with initialized IBOutlets.



For using story board you should init them from story board.
Try to ini controllers next way:



let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) 
let vc = sb.instantiateViewController(withIdentifier: "PostalViewController")


And you should set storyboard id in your story board for the controller, like on the screen below.



storyboard id



Also you can find more info how to init correctly view controllers from storyboard here



What is a StoryBoard ID and how can i use this?






share|improve this answer






















  • Thanks for your response, but still the same results. i have replace in MainNavigationController
    – Nikhil Sawant
    Nov 12 at 15:50










  • Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
    – Gkolunia
    Nov 12 at 15:57











  • let me try it. Thanks
    – Nikhil Sawant
    Nov 12 at 16:05










  • yes i have set the storyboard ID
    – Nikhil Sawant
    Nov 12 at 16:10










  • please, check out my edited post, i've added more information.
    – Gkolunia
    Nov 12 at 16:11















1














IBOulet is set when view controller is initialized with nib file.
So you need create the view controllers using the init method below



init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)


For example, if name of your xib file where you config your IBOultets the same as controllers name, you can just do next:



let postalController = PostalViewController(nibName: "PostalViewController", bundle: nil) 


Here You will have controller with initialized IBOutlets.



For using story board you should init them from story board.
Try to ini controllers next way:



let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) 
let vc = sb.instantiateViewController(withIdentifier: "PostalViewController")


And you should set storyboard id in your story board for the controller, like on the screen below.



storyboard id



Also you can find more info how to init correctly view controllers from storyboard here



What is a StoryBoard ID and how can i use this?






share|improve this answer






















  • Thanks for your response, but still the same results. i have replace in MainNavigationController
    – Nikhil Sawant
    Nov 12 at 15:50










  • Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
    – Gkolunia
    Nov 12 at 15:57











  • let me try it. Thanks
    – Nikhil Sawant
    Nov 12 at 16:05










  • yes i have set the storyboard ID
    – Nikhil Sawant
    Nov 12 at 16:10










  • please, check out my edited post, i've added more information.
    – Gkolunia
    Nov 12 at 16:11













1












1








1






IBOulet is set when view controller is initialized with nib file.
So you need create the view controllers using the init method below



init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)


For example, if name of your xib file where you config your IBOultets the same as controllers name, you can just do next:



let postalController = PostalViewController(nibName: "PostalViewController", bundle: nil) 


Here You will have controller with initialized IBOutlets.



For using story board you should init them from story board.
Try to ini controllers next way:



let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) 
let vc = sb.instantiateViewController(withIdentifier: "PostalViewController")


And you should set storyboard id in your story board for the controller, like on the screen below.



storyboard id



Also you can find more info how to init correctly view controllers from storyboard here



What is a StoryBoard ID and how can i use this?






share|improve this answer














IBOulet is set when view controller is initialized with nib file.
So you need create the view controllers using the init method below



init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)


For example, if name of your xib file where you config your IBOultets the same as controllers name, you can just do next:



let postalController = PostalViewController(nibName: "PostalViewController", bundle: nil) 


Here You will have controller with initialized IBOutlets.



For using story board you should init them from story board.
Try to ini controllers next way:



let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) 
let vc = sb.instantiateViewController(withIdentifier: "PostalViewController")


And you should set storyboard id in your story board for the controller, like on the screen below.



storyboard id



Also you can find more info how to init correctly view controllers from storyboard here



What is a StoryBoard ID and how can i use this?







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 16:12

























answered Nov 12 at 15:35









Gkolunia

828




828











  • Thanks for your response, but still the same results. i have replace in MainNavigationController
    – Nikhil Sawant
    Nov 12 at 15:50










  • Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
    – Gkolunia
    Nov 12 at 15:57











  • let me try it. Thanks
    – Nikhil Sawant
    Nov 12 at 16:05










  • yes i have set the storyboard ID
    – Nikhil Sawant
    Nov 12 at 16:10










  • please, check out my edited post, i've added more information.
    – Gkolunia
    Nov 12 at 16:11
















  • Thanks for your response, but still the same results. i have replace in MainNavigationController
    – Nikhil Sawant
    Nov 12 at 15:50










  • Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
    – Gkolunia
    Nov 12 at 15:57











  • let me try it. Thanks
    – Nikhil Sawant
    Nov 12 at 16:05










  • yes i have set the storyboard ID
    – Nikhil Sawant
    Nov 12 at 16:10










  • please, check out my edited post, i've added more information.
    – Gkolunia
    Nov 12 at 16:11















Thanks for your response, but still the same results. i have replace in MainNavigationController
– Nikhil Sawant
Nov 12 at 15:50




Thanks for your response, but still the same results. i have replace in MainNavigationController
– Nikhil Sawant
Nov 12 at 15:50












Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
– Gkolunia
Nov 12 at 15:57





Sorry, I didn't notice that you use story board, try to create PostalViewController with next code let sb = UIStoryboard(name: "MainStoryboard", bundle: nil) let vc = sb.instantiateViewController(withIdentifier: "PostalViewController") if you set storyboard id for the controller.
– Gkolunia
Nov 12 at 15:57













let me try it. Thanks
– Nikhil Sawant
Nov 12 at 16:05




let me try it. Thanks
– Nikhil Sawant
Nov 12 at 16:05












yes i have set the storyboard ID
– Nikhil Sawant
Nov 12 at 16:10




yes i have set the storyboard ID
– Nikhil Sawant
Nov 12 at 16:10












please, check out my edited post, i've added more information.
– Gkolunia
Nov 12 at 16:11




please, check out my edited post, i've added more information.
– Gkolunia
Nov 12 at 16:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265050%2fchanging-root-view-controllers-gives-iboutlet-as-nil%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto