我有一个ViewControllerA
,它已经显示为弹出,它以模态方式存在。在这个 ViewControllerA
内部有一个 tableview
和 tableViewCell
。因此每个单元格中都有一个 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/