0

持っているUITableViewRowActionので、スライドすると3つのオプションから選択できます。ボタンをクリックするCallと、新しいViewControllerものが画面全体に表示されます。そして、 new 内のボタンをクリックすると、ViewController それを却下したいと思います

[呼び出し] ボタンをクリックすると、ViewController がポップオーバーとして開きます 私のUITableViewRowAction

これは、ボタンをクリックした後に開き、下部の x ボタンをクリックすると閉じます。 ポップオーバーとしての私の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
    })

コードは非常に混沌としていると思いますが、アプリのプログラミングはまだ得意ではありません。

皆様のご尽力に感謝いたします。

4

2 に答える 2

0

このコードを試してください: Swift 3 でテスト済み。

メインVC:

  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
  }

  func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
    return true
  }

  func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    let callAction = UITableViewRowAction(style: UITableViewRowActionStyle.normal, title: "Call") { (UITableViewRowAction, NSIndexPath) -> Void in
        self.performSegue(withIdentifier: "callSegue", sender: self) 
    }

    let videoAction = UITableViewRowAction(style: UITableViewRowActionStyle.normal, title: "Video") { (UITableViewRowAction, NSIndexPath) -> Void in
    }

    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.normal, title: "Delete") { (UITableViewRowAction, NSIndexPath) -> Void in  
    }

    callAction.backgroundColor = .blue
    videoAction.backgroundColor = .green
    deleteAction.backgroundColor = .red

    return [deleteAction,videoAction,callAction]

}

DestVC

@IBAction func dissmissButton(_ sender: UIButton) {

    dismiss(animated: true, completion: nil)
}
于 2016-10-30T10:59:39.883 に答える