UITableviewController 触摸时不显示菜单

UITableviewController not showing Menu on touch

请查看我的代码并提出更正建议或我需要进行的任何类型的代码更改,以便在选定的 table 行上显示菜单。请帮忙,我是 iOS.

的新手
import UIKit

class CutomerHomeTab: UITableViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    addCustomMenuItems()

    }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func addCustomMenuItems() { //CUSTOM MENU IMPLEMENTED

    let menuController = UIMenuController.sharedMenuController()
    var newItems = menuController.menuItems ?? [UIMenuItem]()


    newItems.append(UIMenuItem(title: "Abort", action: MenuAction.Abort.selector()))
    newItems.append(UIMenuItem(title: "Accomplish", action: MenuAction.Accomplish.selector()))
    menuController.menuItems = newItems
}


enum MenuAction:String{
    case Accomplish = "Accomplish:"         //ENUMERATED DATA TYPES DECLARATION FOR MENUACTION
    case Abort = "Abort:"

                  //We need this awkward little conversion because «enum»'s can only have literals as raw value types. And «Selector»s aren't literal.
    func selector()->Selector{
        return Selector(self.rawValue)
                                                        //IMPLEMENTATIION OF       SELECTOR FUNCTION
    }        //END OF SELECTOR FUNCTION
}            //END OF ENUM DECLARATION

func Accomplish(sender:AnyObject?){
    print("Did something new!accomplished")     //FUNCTION FOR IMPLEMENTATION OF ACCOMPLISH
}
func Abort(sender:AnyObject?){
    print("Did something new!aborted")           //FUNCTION FOR IMPLEMENTATION OF ABORT
}


override func tableView(tableView: UITableView, canPerformAction action: Selector, forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) -> Bool {//FUNCTION TO LET USER PERFORM ACTION ON THE GIVEN ROW
    return action == MenuAction.Accomplish.selector() || action == MenuAction.Abort.selector()
}

override func tableView(tableView: UITableView, performAction action: Selector, forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) {
    //You can handle standard actions here, but custom actions never trigger this. It still needs to be present for the menu to display, though.
}

 override func tableView(tableView: UITableView, shouldShowMenuForRowAtIndexPath indexPath: NSIndexPath) -> Bool {   ///FUNCTION FOR SELECTION OF ROW
    return true
}




override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 7
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

    return cell
}




}

UIMenuController 应用程序单例负责呈现编辑操作菜单项,例如复制、剪切、删除、Select 等。有很棒的NSHipster tutorial about it. I'm afraid Accomplish and Abort is not actually edit actions. So I guess using UIMenuController is not completely right decision. If you want to propose user some options on tapping table view's cell you should better use UIActionSheet. If you want to display options in the exact same way as UIMenuController does, I would rather suggest you to consider using some CocoaPod like https://github.com/camelcc/MenuPopOverView