Removing default cut, copy, paste from UIMenuController in a TableView

后端 未结 2 688
深忆病人
深忆病人 2021-01-12 21:51

I\'m trying to remove the default menu items from UIMenuController. I found this post for UIWebview or UITextView:

How to remove the default UIMenuItem from the UIM

相关标签:
2条回答
  • 2021-01-12 22:36

    The table view delegate method -tableView:canPerformAction:forRowAtIndexPath:withSender: is for this purpose exactly.

    Here is an example:

    override func tableView(tableView: UITableView, canPerformAction action: Selector, forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) -> Bool {
        switch action {
        case Selector("cut:"), Selector("copy:"), Selector("paste:"):
            return false // as per your question
        case Selector("myAction:"):
            return true
        default:
            return false
        }
    }
    
    0 讨论(0)
  • 2021-01-12 22:39

    Use this code to remove the default features of cut, copy, paste and select:

    (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        UIMenuController * menuContoller=[UIMenuController sharedMenuController];    
        if (menuContoller) 
        {
            [UIMenuController sharedMenuController].menuVisible=NO;
        }
        return NO;
    }
    
    0 讨论(0)
提交回复
热议问题