Search code examples
iosstoryboard

Identify which Storyboard is active


I need to work out how to identify what storyboard is active at any given time. I have a specialised nativation in which I need to identify the storyboard (UIView) then change things programmatically depending on what the user presses.

  1. All storyboards have Identifiers.
  2. in the viewDidLoad of the root view I have the following.
- (void)viewDidLoad
 self.topViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"View1"];
{

What I would like to do is identify which storyboard the user is on and depending on the press do the following sudo-code

- (void)viewDidLoad
if (storyboard.name != RootView)
   self.topViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"View1"];
{
else if (storyboard.name = View2){
   self.topViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"View2"];
}

etc....

I have step through the code and seen the StoryboardID however it's which I'm pretty sure your not meant to use....

Thanks in advance Jeremy

UPDATE: Explanation to Navigation

I'm trying to implement the ECSlideViewController, but It's doing my head in. Effectively adding in the slide to the right function to reveal more options. SO, this thinking was going to be easy turned out icky. I have the master UIViewController<title:HomeView> I then have 4 buttons on the screen which segueway to other UIViewControllers<View1>, UIViewController<View2> etc.

In order to produce the effect on View1,View2,View3,View4 I need to bring the class (ECSlideViewController as per the example) into the UIViewController<HomeView>. However If I change the below code to represent this...

self.topViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"HomeView"]; 

It crashes because it calls itself. Not good, circular coding is a no no.

but if I set it to what was originally there

self.topViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];

( btw firstTop is the title of the view used with the example)

It works but then disregards the UIViewController<HomeView>

This is why I asked if there was a way to identify the self.title of the UIViewController(said storyboard...my bad) as I was going to put conditional logic around it in order to not put the code in if it's on the UIViewController<HomeView>.

It really is hard to explain unless you download the ECSlideViewController and start playing with it. But effectively I just want to test the self.title.....I think...

The other idea was to bring the logic into the UIViewControllers of the four and get it to work there...but It freaks out passing nil as it's expecting an identifier...

Hope this makes sense....

J.


Solution

  • Okay Guys,

    Totally ditched ECSlideViewController. I found a few articles explaining that it had issues when you had multiple UiViewControllers not passing data correctly. I ended up using Andrews suggestion. http://www.youtube.com/feed/UCJA_puohXgnze8gPaerTeig It worked for easier for me.

    Although I take note of what the design guidelines Apple have an this is usually a no no, but I'm hoping that they won't mind.

    Thanks everyone again!

    J.