当按下视图上的任何按钮时,canPerformAction将被触发。但是我只想选择一个文本就触发它

时间:2018-06-30 13:43:27

标签: selector uimenucontroller uiresponder

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
//i am trying to send the selected text to another viewController with alert and action    
        var range = questionTextView.selectedTextRange
        let selectedText = questionTextView.text(in: range!)      
        if range != nil {
            let alert = UIAlertController(title: selectedText, message: "", preferredStyle: .actionSheet)
            let action = UIAlertAction(title: "KELİME DEFTERİNE EKLE", style: .default) { action in

                self.newWords.append(words(word: selectedText!))
                let propertyList = PropertyListEncoder()
                do { let encoded = try? propertyList.encode(self.newWords)
                    try? encoded?.write(to: wordssarchiveURL)

                }

                print(selectedText!)
                print(self.newWords)

            }
            alert.addAction(action)
            present(alert, animated: true,completion: nil)
            range = nil
        }

    return true
}

0 个答案:

没有答案