我有一个UITableViewRowAction
所以当我滑动时,我可以选择 3 个选项。如果我单击Call
按钮,我希望ViewController
在整个屏幕上弹出一个新按钮。如果我点击 new 里面的一个按钮,ViewController
我希望它被解雇。
单击 Call 按钮会打开一个 ViewController 作为弹出窗口
这是我的代码
func buttonToDismiss (sender: AnyObject) {
self.presentedViewController?.dismiss(animated: true, completion: nil)
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let callButton = UITableViewRowAction(style: .default, title: "Call", handler: { (action, indexPath) in
self.tableView.dataSource?.tableView?(
self.tableView,
commit: .delete,
forRowAt: indexPath)
let vc = UIViewController(nibName: nil, bundle: nil)
vc.view.frame = CGRect(x: 0, y: 0, width: 100, height: 200)
vc.view.backgroundColor = UIColor(red: 62/255.0, green: 70/255.0, blue: 80/255.0, alpha: 1.0)
vc.modalPresentationStyle = .popover
let declineButton = UIButton()
declineButton.frame = CGRect(x: 150, y: 484, width: 75, height: 75)
declineButton.backgroundColor = UIColor(red: 36/255.0, green: 44/255.0, blue: 55/255.0, alpha: 1.0)
declineButton.tintColor = UIColor.white
declineButton.layer.cornerRadius = declineButton.frame.size.height / 2
declineButton.layer.masksToBounds = true
declineButton.clipsToBounds = true
declineButton.setTitle("X", for: .normal)
declineButton.addTarget(self, action: Selector(("buttonToDismiss:")), for: UIControlEvents.touchUpInside)
vc.view.addSubview(declineButton)
let popover = vc.popoverPresentationController!
let cell = tableView.cellForRow(at: indexPath)!
var cellAbsolutePosition = cell.superview!.convert(cell.frame.origin, to: nil)
cellAbsolutePosition.x = cell.frame.width - 60
popover.sourceRect = CGRect(origin: cellAbsolutePosition, size: cell.frame.size)
popover.sourceView = tableView
self.present(vc, animated: true, completion: nil)
return
})
我知道我认为代码很混乱,但我还不太擅长编写应用程序。
感谢您的帮助,并提前感谢您的努力。