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

夙愿已清 提交于 2019-12-04 01:24:31

问题


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!


回答1:


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
    }
}



回答2:


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;
}


来源:https://stackoverflow.com/questions/10505755/removing-default-cut-copy-paste-from-uimenucontroller-in-a-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!