ios - 关闭弹出 View

标签 ios swift

我以编程方式添加了一个弹出 View ,当我单击弹出窗口中的按钮时,它将显示另一个警报 View Controller 。但问题是我无法忽略最初添加的弹出 View 。它仍然显示在警报 View 后面。谁能帮我解决这个问题吗?

使用下面的代码,我创建了弹出 View 。

   let storyboard : UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
        let menuViewController: PopupViewController = storyboard.instantiateViewControllerWithIdentifier("Popup") as! PopupViewController
        menuViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
        menuViewController.preferredContentSize = CGSizeMake(300, 275)

        let popoverMenuViewController = menuViewController.popoverPresentationController
        popoverMenuViewController?.delegate = self
        popoverMenuViewController?.sourceView = self.view
        // If wants the arrow head remove the below line code
        popoverMenuViewController?.permittedArrowDirections = UIPopoverArrowDirection()
        popoverMenuViewController?.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
        presentViewController(menuViewController,animated: true,completion: nil)

最佳答案

这可能对你有帮助

let alertController = UIAlertController(title: "My alert", message: "some text...", preferredStyle: .Alert)
// .Default will dismiss the alert automatically
let myAlertAction = UIAlertAction(title: "Alert", style: .Default, handler: { (UIAlertAction) in
    // Some stuff, present your other alert
    // self.myMainViewController.presentViewController...
 })
alertController.addAction(myAlertAction)

我就是这么做的,效果很好

关于ios - 关闭弹出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908770/

相关文章:

ios - 需要更改启动时显示的 View

ios - 无法使用 '[Array<String>]' 类型的索引为 '(section)' 类型的值添加下标。类型'(又名 'section.Type' )

ios - 显示 Tableview 的最后一个单元格

swift - 如何捕获通过 SwiftUI 中的函数更改的值更改?

ios - 在函数中将 Int 设置为 1 后,viewWillAppear 中的 Int 为 nil - Swift

swift - 当自定义展开/折叠日期选择器位于表格 View 的底部单元格时,它会展开 View - Swift

ios - 如何在 iOS 设备上测试慢速后台线程

ios - 'sd_setImage(with:placeholderImage:completed:)' 与 Swift 3 的不明确使用

xcode - 带有 Swift 的 xcode 6 中的 iAd

iOS 框架 - 使用未声明的标识符