在表格视图单元格中单击按钮时显示弹出菜单

时间:2019-02-10 11:58:37

标签: swift uitableview popupmenu

enter image description here

我试图在单击放置在表格视图单元格中的按钮时显示一个弹出菜单。问题是在前6行之后,弹出菜单出现在其他位置.....?如何正确显示?

我正在使用Cocoapod(SwiftPopMenu)显示弹出菜单。

@IBAction func MenuButton(_ sender: UIButton)
{
            print(VideoName_For_ContextMenu)
            let buttonPostion = sender.convert(sender.frame.origin, to: tableview)
            showMenu(x:buttonPostion.x, y:buttonPostion.y, VideoName: VideoName_For_ContextMenu)
}.   

 func showMenu(x:CGFloat,y:CGFloat,VideoName:String)
    {

        popMenu = SwiftPopMenu(frame:  CGRect(x: KSCREEN_WIDTH-185, y: y+200, width: 180, height: 112))


        popMenu.popData = [(icon:"TrashBin",title:"Delete"),
                           (icon:"Bookmark",title:"Add BookMarks")]

        popMenu.didSelectMenuBlock =
        {
            [weak self](index:Int)->Void in
            self?.popMenu.dismiss()
            print("block select \(index)")

            if index == 0
            {
                self!.DeleteMyVideos(VideoNames: VideoName)

                DispatchQueue.main.async
                {
                    let alert  = UIAlertController(title: "Success", message: "Your Video has been Deleted.....!", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                    self!.present(alert, animated: true, completion: nil)

                    self!.getData()

                    self!.tableview.reloadData()
                }

            }
        }

0 个答案:

没有答案
相关问题