持っているUITableViewRowAction
ので、スライドすると3つのオプションから選択できます。ボタンをクリックするCall
と、新しいViewController
ものが画面全体に表示されます。そして、 new 内のボタンをクリックすると、ViewController
それを却下したいと思います。
[呼び出し] ボタンをクリックすると、ViewController がポップオーバーとして開きます
これは、ボタンをクリックした後に開き、下部の x ボタンをクリックすると閉じます。
これは私のコードです
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
})
コードは非常に混沌としていると思いますが、アプリのプログラミングはまだ得意ではありません。
皆様のご尽力に感謝いたします。