简体   繁体   中英

Swift: How to know which Storyboard is active

I am trying to run a function only when a certain storyboard is active.

Example:

    if view == secondStoryboard {   //Don't know what to do here
        functionOnSecondStoryboard("Test")
    }

This may be a very simple fix, thanks for taking a look.

What do you mean by active storyboard? If I understand what you're trying to achieve, you can get the storyboard from which a view controller was instantiated using

let storyboard = self.storyboard
//now you can compare it to other storyboards
if storyboard == storyBoardNumberOne {
}

You can get its name with key-value coding and compare the string names

let name = storyboard?.valueForKey("name")

But be careful using the KVC to get the name - this isn't a documented feature and I cannot guarantee if an app using it would be accepted in the AppStore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM