Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 UIMenuController in iOS?

I'm trying to do this for the new iOS 5 methods where you can show a menu item on the table selection. So my class is a subclass of UIViewController that has a UITableView in it. I wasn't sure how or IF removing the default items was possible. Thanks!

like image 591
Crystal Avatar asked May 08 '12 20:05

Crystal


1 Answers

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
    }
}
like image 77
jrc Avatar answered Sep 21 '22 15:09

jrc