如何删除查找和分享来自Swift 3中的textview

时间:2017-06-02 12:43:21

标签: swift uitextview

我可以使用此

删除剪切,复制,粘贴,选择,全部选择
SourceKitService

但是我无法删除查找&分享

http://en.community.dell.com/support-forums/laptop/f/3518/p/20013495/21000473

有人可以建议我如何删除它吗?

3 个答案:

答案 0 :(得分:4)

如果你真的不想允许任何行动,为什么要专门检查每一项?只需在方法中返回false即可。否则,你可以放置一个断点,看看你为“动作”调用了什么,并为它添加另一个验证

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    print("BlahTextView::canPerformAction: \(action)")
    return false
}

结果,你要删除的2突出显示:

  

BlahTextView :: canPerformAction:cut:   BlahTextView :: canPerformAction:copy:   BlahTextView :: canPerformAction:选择:   BlahTextView :: canPerformAction:selectAll:   BlahTextView :: canPerformAction:paste:   BlahTextView :: canPerformAction:delete:   BlahTextView :: canPerformAction:_promptForReplace:   BlahTextView :: canPerformAction:_transliterateChinese:   BlahTextView :: canPerformAction:_showTextStyleOptions:   BlahTextView :: canPerformAction: _lookup :   BlahTextView :: canPerformAction:_define:   BlahTextView :: canPerformAction:_addShortcut:   BlahTextView :: canPerformAction:_accessibilitySpeak:   BlahTextView :: canPerformAction:_accessibilitySpeakLanguageSelection:   BlahTextView :: canPerformAction:_accessibilityPauseSpeaking:   BlahTextView :: canPerformAction: _share :   BlahTextView :: canPerformAction:makeTextWritingDirectionRightToLeft:   BlahTextView :: canPerformAction:makeTextWritingDirectionLeftToRight:

然后你可以这样做:

override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(copy(_:)) ||
        action == #selector(paste(_:)) ||
        action == #selector(select(_:)) ||
        action == #selector(selectAll(_:)) ||
        action == #selector(cut(_:)) ||
        action == Selector(("_lookup:")) ||
        action == Selector(("_share:")) ||
        action == Selector(("_define:"))
    {
        return false
    }
    return super.canPerformAction(action, withSender: sender)
}

需要替代语法,因为这些方法未公开声明,如果使用#selector( share( :)),则会出现编译器错误。

查找 - 请使用((_define :))谢谢。

答案 1 :(得分:2)

// Make sure 
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(select(_:))
    {
        return true
    } else {
        return false
    }
}

答案 2 :(得分:1)

正如您在一个答案的评论中提到的那样,您想要启用select,那么为什么不比较select并返回true以及false其他情况。

override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(select(_:)) {
        return true
    }
    return false
}