swift - Swift 中标签词选择的动态弹出窗口

标签 swift uiviewcontroller popup appdelegate deep-linking

我正在寻找一种方法,当用户在标签中选择特定单词时,在 View Controller 中动态显示弹出窗口。

例如

点击here如需链接,请点击here另一个链接

标签文本是从数据库中提取的,因此是根据用户正在查看的内容动态添加的,我希望使用 Swift 中的 URL 方案来根据用户选择的内容显示正确的弹出窗口,但是当我添加时以下应用程序委托(delegate)中的弹出窗口显示在单独的 View Controller 中,而不是作为弹出 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

当弹出窗口关闭时,后面的屏幕现在是空白的,而不是显示原始 View Controller 。

所以我的问题是,这是否是实现此目标的最佳方法,因为我不确定在应用程序中使用 URL 链接链接到同一应用程序的其他部分的最佳实践,或者是否还有其他我缺少的方法。

最佳答案

我想我现在已经解决了这个问题,使用以下方法;

    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)

关于swift - Swift 中标签词选择的动态弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40302101/

相关文章:

javascript - 如何关闭在其外部单击的div

ios - 是否可以像在 Vuforia 中那样在 ARKit 中跟踪对象?

ios - Tab Bar隐藏包含CollectionViewController的CustomView

ios - 协议(protocol)委托(delegate)有时不工作

ios - 推送 View Controller ,但返回另一个

objective-c - Swift 中的 MFMailComposeViewController

iOS:删除位于 UITableView 之上的 UIView 会导致无法与表格交互

xamarin - 在 Xamarin.Forms 中,如何使用 RG.Plugin 在所需位置设置弹出页面?

ios - 在 iOS 应用程序上控制语言

ios - Splash 完成后更改 ViewController