2017-04-20 7 views
0

ビューにiosコピー・ボタンを表示し、カスタム・ファンクションのクリックを処理しようとしています。このコードでボタンを表示しようとしましたが、何も表示されません。ビューにコピー・メニューを表示

let menu = UIMenuController.shared 
        if !menu.isMenuVisible { 
         menu.setTargetRect(paragraphTableViewCell.bounds, in: paragraphTableViewCell) 
         menu.setMenuVisible(true, animated: true) 
        } 

EDIT:

私はあなたがあなたのクラスではcanBecomeFirstResponderを呼び出す必要があり、このエラー

enter image description here

答えて

0

を得ました。あなたがのUIViewを渡す必要があり

そして上書きcanPerformActionは、としてUIMenuItem最後

func canBecomeFirstResponder() -> Bool { 
    return true 
} 

override func canPerformAction(_ action: Selector, withSender sender: Any) -> Bool { 
    if action == #selector(self.cut) { 
     return false 
    } 
    else if action == #selector(self.copy) { 
     return true 
    } 
    else if action == #selector(self.paste) { 
     return false 
    } 
    else if action == #selector(self.select) || action == #selector(self.selectAll) { 
     return true 
    } 
    else { 
     return super.canPerformAction(action, withSender: sender) 
    } 

} 



override func copy(_ sender: Any?) { 

} 

をあなたの適切なオプションを追加しオブジェクト

menu.setTargetRect(paragraphTableViewCell.bounds, in: paragraphTableViewCell.contentView) 

理由は、その

- (void)setTargetRect:(CGRect)targetRect inView:(UIView *)targetView; 
0を必要と
+0

ありがとうございます。コードを貼り付けるときにエラーが発生しました。質問を更新しました。 – user567

+0

更新された回答を確認する – karthikeyan

関連する問題