如何通过模态呈现视图控制器来呈现操作表?

时间:2018-04-01 15:27:15

标签: ios swift4

我有一个ViewControllerA已经显示为pop out,它以模态显示。在ViewControllerA内,tableviewtableViewCell。每个单元格中都有button。当用户点击此button时,我想显示{{} 1}}在屏幕的底部。

这是我的代码:

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

actionSheet

ViewControllerA

protocol MyDelegate: class {
    func showDropDownMenu()
}

class tableCell: UITableViewCell {

    weak var delegate: MyDelegate?

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

}

假设点击该按钮时会调用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) } 中的showDropDownMenu()功能。现在我点击ViewControllerA它会在控制台中显示dropDownButton(表示没问题按钮),但print something没有显示在底部。

我不确定这里有什么问题,但我怀疑actionSheet使用ViewControllerA时会出现这样的问题:{/ p>

  

种类:以模态呈现,演示:过流背景,过渡:   覆盖垂直

如果这是原因,请帮助我如何从以模态方式呈现的视图控制器中呈现操作表。谢谢

显示ViewControllerA的代码:

segue

2 个答案:

答案 0 :(得分:1)

请参阅此链接。虽然它适用于iPad,但它会让您简要了解在何处以及如何呈现活动表

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

我遇到了类似的情况,你想要实现的目标,我上面提供的这个解决方案帮助了我。希望,它也可以帮助你。

答案 1 :(得分:0)

确保您为delegate设置了值。例如

cell.delegate = self;
相关问题