ios - 如何从模态呈现的 View Controller 呈现操作表?

标签 ios swift4

我有一个ViewControllerA,它已经显示为弹出,它以模态方式存在。在这个 ViewControllerA 内部有一个 tableviewtableViewCell 。因此每个单元格中都有一个 button 。当用户单击此按钮时按钮,我想在屏幕底部显示actionSheet

这是我的代码:

TableViewCell类,这里我将按钮连接到IBAction

protocol MyDelegate: class {
    func showDropDownMenu()
}

class tableCell: UITableViewCell {

    weak var delegate: MyDelegate?

    @IBAction func dropDownButton(_ sender: Any) {
        print("print something")
        self.delegate?.showDropDownMenu()
    }

}

ViewControllerA

class ViewControllerA: UIViewController , UITableViewDataSource, UITableViewDelegate,MyDelegate {

func showDropDownMenu() {

    let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

    // Create your actions - take a look at different style attributes
    let hideAction = UIAlertAction(title: "Hide", style: .default) { (action) in
         print("didPress hide")      
     }

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
       print("didPress cancel")
    }


     actionSheet.addAction(hideAction)
     actionSheet.addAction(cancelAction)

     self.present(actionSheet, animated: true, completion: nil)
}

假设点击按钮时会调用ViewControllerA中的showDropDownMenu()函数。现在我点击dropDownButton它会显示在控制台中打印一些内容(意味着按钮没有问题),但是actionSheet没有显示在底部。

我不确定这里的问题是什么,但我怀疑是由于 ViewControllerA 使用 segue 引起的,其属性如下:

Kind: Present modally ,Presentation: Over Current Context ,Transition: Cover Vertical

如果这是原因,请帮助我如何从以模式方式呈现的 View Controller 中呈现操作表。谢谢

显示 ViewControllerA 的代码:

func showViewControllerA(Id: Int) {
   self.performSegue(withIdentifier: "showViewControllerA", sender: Id)
}

最佳答案

请引用此链接。虽然它适用于 iPad,但它会让您简要了解在何处以及如何展示操作表

https://medium.com/@nickmeehan/actionsheet-popover-on-ipad-in-swift-5768dfa82094

我遇到过与您要实现的目标类似的情况,而我在上面提供的这个解决方案帮助了我。希望它也能帮助您。

关于ios - 如何从模态呈现的 View Controller 呈现操作表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49599599/

相关文章:

swift 4 : cast issue with Generics

ios - 如何更改 Xcode 中导航栏项目(特别是按钮)的宽度?

ios - NSMutableAttributedString文本颜色无法正常工作

ios - iTunes iOS 下载错误/无法安装

ios - 您可以在不使用 Storyboard 的情况下在 AutoLayout 控制台输出中标记 View 吗?

ios - 如何使搜索栏在表格 View 中滚动时不消失?

ios - Swift Wordpress 帖子获取页面

ios - TableView 位于另一个 TableView 的标题内

ios - 滚动或重新加载表格 View 后查看位置变化

iphone - 如何从Cocos2D返回UIkit?