我有一个UITableViewRowAction
所以当我滑动时,我可以选择3个选项。如果我点击Call
按钮,我想要一个新的ViewController
来弹出整个屏幕。如果我点击新ViewController
内的按钮,我希望将其解除。
单击“调用”按钮,将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
})
我知道代码是我认为非常混乱,但我还不是很擅长编程应用程序。
我感谢您的帮助,并提前感谢您的努力。
答案 0 :(得分:0)
这样做而不是你在做什么:
SELECT
c0.*, p1."id" FROM "c0" AS c0
LEFT JOIN "p1" AS p1
ON p1."id" = 2
LEFT JOIN "c2" AS c2
ON c2."p1" = p1."id"
WHERE (c2."c1_id" = c0."id")
GROUP BY c0."id", p1."id"
时要显示的ViewController
call action
按钮放在dismiss
上并将其连接到ViewController
IBAction
时,从call action
实例化ViewController
并简单地展示这是一个简单的例子:
在ViewController
ViewController
call action
只需使用func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
var rowActions = [UITableViewRowAction]()
let callAction = UITableViewRowAction.init(style: .default,
title: "Call") { (action, cellPath) in
//instantiate the view controller with storyboard ID
let vc = self.storyboard?.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
self.present(vc, animated: true, completion: {
})
}
rowActions.append(callAction)
return rowActions
}
IBAction
答案 1 :(得分:0)
试试这段代码:在Swift 3中测试。
<强> MainVC:强>
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)
}