ScoopMatt
ScoopMatt

Reputation: 79

Dynamic Popups in Swift on label word selection

I'm looking for a way to show a dynamically show a popup within a view controller when a user selects a particular word within a label.

The label text is pulled from a database so is dynamically added based on the content a user is viewing, i was hoping to use the URL schemes within Swift to show the correct popup depending on what a user selected, but when i add the following within app delegate the popup shows within a separate view controller and not as a pop up view controller.

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    
    let navVC = storyboard.instantiateViewControllerWithIdentifier("glossaryPopupID") as! UIViewController
    
    self.window?.rootViewController?.presentViewController(navVC, animated: true, completion: nil)
    return true

When the popup is close the screen behind is now blank rather than showing the original view controller.

SO my question is, whether this is the best way to achieve this as im not sure its best practice to used URL links within an app to link to other parts of the same app, or is there another way i am missing.

Upvotes: 0

Views: 578

Answers (1)

ScoopMatt
ScoopMatt

Reputation: 79

Think i have resolved this now, using the following;

    let storyboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("test") as! ViewController
    let popOverVC = UIStoryboard(name:"Main", bundle: nil).instantiateViewControllerWithIdentifier("sbPopUpID") as! PopUpViewController
    storyboard.addChildViewController(popOverVC)
    popOverVC.view.frame = storyboard.view.frame
    storyboard.view.addSubview(popOverVC.view)
    popOverVC.didMoveToParentViewController(storyboard)
    self.window?.rootViewController?.presentViewController(storyboard, animated: true, completion: nil)

Upvotes: 0

Related Questions