Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data to the view controller that UINavigationController points to

So heres my question. I am a silent stackoverflow skimmer and Im using xcode 4.5 storyboards for an application which starts with a view controller which asks for the username and password. My application checks data via a backend server and then if the login is correct it performs a segue which points to the uinavigationcontroller which forwards the screen to the main menu.... The uinavigationcontroller hasnt been tampered with and pushes the mainmenu automatically.

Login_screen -> UINavigationController -> Main_Menu

My question is how do i pass the NSString username from the login screen to the main menu screen.

I understand how to pass data from one screen to the next when the segue is pointing directly to it via the prepareforsegue method as well as performsegue. But in this case the login_screen segue points to the uinaviationcontroller which points to the main_menu controller

My assumption is that i will need to make a custom class which inherits UINavigationController and implement certain methods but since uinavigationcontroller isnt seen i dont think viewdidload or viewwillappear are the right methods.

Any help will be appreciated

I am a new user so i am not allowed to post images but i will fix that as soon as possible

like image 321
Rohan Panchal Avatar asked Jan 15 '23 04:01

Rohan Panchal


1 Answers

You can use the topViewController property of the UINavigationController.

Cast the UINavigationController.topViewController object to Main_MenuViewController and set the data normally.

Hope this helps

like image 88
vassilag Avatar answered Jan 27 '23 19:01

vassilag