简体   繁体   中英

How do I get the string name of a storyboard?

I've already looked at the following for guidance to no avail:

How to know the current storyboard name?

I am trying to open a specific view controller using my storyboard from a remote notification based off of the following answer:

Present specific view controller in didReceiveRemoteNotification with Swift

    let mvc = MainViewController()
    let storyBoardNameString = mvc.storyboard. //<-proposed solution? Nothing from auto complete shows up
    let storyboard = UIStoryboard(name: storyBoardNameString , bundle: nil) 
    storyboard.instantiateViewControllerWithIdentifier("some-view-controller")

I've checked the "File inspector", "Quick help inspector", "Identity inspector", "Attributes inspector", "Size inspector", and even the "Connections inspector" with no luck there either.

When I selected a view controller on my storyboard and tried to find the name of the current storyboard I was only able to find the view's Storyboard ID, not the name of the storyboard however.

Any solution would be greatly appreciated, otherwise I will try to find another way to accomplish my task.

My colleague just informed me it's the name of the file without the ".storyboard" extension. Regards.

Try following code it may helps you.

let mvc = MainViewController()
let storyBoardNameString = mvc.restorationIdentifier!//it will give identifier
let storyboard = UIStoryboard(name: storyBoardNameString , bundle: nil) 
storyboard.instantiateViewControllerWithIdentifier("some-view-controller")

Maybe my answer is not right to your question, but you can take a look and think about it.

Make a payload format, and create the specific UIViewController with it.

let payload = ["storyboard" : "StoryboadNameYouWant", "viewcontroller" : "ViewControllerName", "parameters" : "YourParameters"]


func handlePayload(payload: Dictionary<String, String>) {
     let storyboard = UIStoryboard(name: payload["storyboard"]!, bundle: nil)
     let vc = storyboard.instantiateViewControllerWithIdentifier(payload["viewcontroller"]!)
     // present vc
}

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