Identify which Storyboard is active

倖福魔咒の 提交于 2019-12-13 18:17:17

问题


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 I then have 4 buttons on the screen which segueway to other UIViewControllers, UIViewController 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. 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 first op is the title of the view used with the example)

It works but then disregards the UIViewController

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.

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.


回答1:


I'm not sure if this helps, but it sounds like you will have to compare instances to get the results you are looking for. I haven't tried this, but I would create properties of each storyboard in your app delegate, then reference the app delegate in your view controller to compare. This might not be the best coding practices, but I'll leave that into your hands.

Something like (untested code):

- (void)testStoryBoard //After awake from nib or viewDidLoad
 {
    NXAppDelegate *appDelegate = (NXAppDelegate *)[[UIApplication sharedApplication] delegate];
    if ([self.storyBoard isEqual:appDelegate.view1StoryBoard]) 
         NSLog(@"View1 Storyboard");
    else 
         NSLog(@"View 2 Storyboard");
 }



回答2:


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.



来源:https://stackoverflow.com/questions/14928817/identify-which-storyboard-is-active

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!