IOS storyboards instantiate viewController and IBAction?

If you've set up your initial view controller properly in the storyboard, you don't need to assign it to the windows rootViewController property in -applicationDidFinishLaunchingWithOptions: as this is done for you automatically. It sounds like you're creating a second instance. To access the original instance setup by the storyboard simply do this in -applicationDidFinishLaunchingWithOptions.

Up vote 0 down vote favorite share g+ share fb share tw.

I may go mad very soon. This is the reason: - I started up with Single View Application project with storyboards. Then I set the view controller class name in the storyboard for my viewController.

- Next step I created one pointer for this viewController in AppDelegate method ...didFinishLaunchingWithOpt... and filled it up by calling myStoryboards instantiate.... It works pretty good because I can call method like vc1 setMyName which does smthng like self. MyName = @"Johnny"; - But here it comes. When I create IBAction method joined with button, this method doesn't know anything about "Johhny".

And this is because I'm in another instance. When I check the address of "self" it is another one... WhyWhyWhy? Please help, how can I use still the same object - the one instantiated in AppDelegate by storyboards and the one from storyboards in "interface builder".

Thank you. Oh my. I think I really underestamated it... When we were talking about getting pointer of other viewControllers from storyboard... I have initialViewController got by calling rootViewContr... And another one connected with segue (modal) where is UITableView.

A get data on rootViewController and I want to show them on the other one in the list (UITableView). So I call segue (performSegueWithIdentifier), the other controller is shown but the list is clear. Because the method I call is working with tableView variable which is null :/ Because, again, I'm in another object.

That is because I call that method storyboard instantiate... How can I get exactly the same viewController which I'm working in storyboard with. It is quite confusing for me :/ I read something about prepareForSegue and getting the pointer by destinationViewController but that is not what exactly I want. I need the pointer before I call segue method and the viewController is shown... Thank you.

Ios storyboard programmatically instantiate link|improve this question edited Dec 11 '11 at 18:41Kev?36k464132 asked Dec 9 '11 at 21:45D33133 20% accept rate.

If you've set up your initial view controller properly in the storyboard, you don't need to assign it to the windows rootViewController property in -applicationDidFinishLaunchingWithOptions: as this is done for you automatically. It sounds like you're creating a second instance. To access the original instance setup by the storyboard simply do this in -applicationDidFinishLaunchingWithOptions: InitialViewController *viewController = (InitialViewController *)self.window.

RootViewController; viewController. MyName = @"Johnny.

GREAT! Thank you. That's it.

I knew I was working with second instance. But didn't know how to avoid it. OK.

So similar question using new facts. What about situation when I have two viewControllers. Is there a chance to get the pointer in the way you described?

– D33 Dec 9 '11 at 22:12 Only the view controller marked as the 'Initial View Controller' in the storyboard will be instantiated by the time -applicationDidFinishLaunchingWithOptions: is sent. If you need references to other view controllers, you need to instantiate them with the methods on UIStoryboard. – Mark Adams Dec 9 '11 at 22:17 Yes.

I get it. And it works! So really big "thank you" to you – D33 Dec 9 '11 at 22:32 1 You're welcome!

Nothing says thank you like a big green checkmark though... ;) – Mark Adams Dec 9 '11 at 22:41.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions