diff --git a/TagNameDetection/TagNameDetection.xcodeproj/project.xcworkspace/xcuserdata/datt.xcuserdatad/UserInterfaceState.xcuserstate b/TagNameDetection/TagNameDetection.xcodeproj/project.xcworkspace/xcuserdata/datt.xcuserdatad/UserInterfaceState.xcuserstate index 763ef6c..4311a9d 100644 Binary files a/TagNameDetection/TagNameDetection.xcodeproj/project.xcworkspace/xcuserdata/datt.xcuserdatad/UserInterfaceState.xcuserstate and b/TagNameDetection/TagNameDetection.xcodeproj/project.xcworkspace/xcuserdata/datt.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TagNameDetection/TagNameDetection/DPTagTextView/DPTagTextView.swift b/TagNameDetection/TagNameDetection/DPTagTextView/DPTagTextView.swift index bf2562b..7ada3be 100644 --- a/TagNameDetection/TagNameDetection/DPTagTextView/DPTagTextView.swift +++ b/TagNameDetection/TagNameDetection/DPTagTextView/DPTagTextView.swift @@ -140,6 +140,7 @@ class DPTagTextView: UITextView , UITextViewDelegate { func setTxt(_ str:String) { arrRange = [Range]() var strTemp = str + if arrTags.count == 0 { arrTags = getAllTag(str) } for _ in arrTags { if let strTag = strTemp.slice(from: tagPrefix, to: tagPostfix) { for range in strTemp.ranges(of: "\(tagPrefix)\(strTag)\(tagPostfix)") { diff --git a/TagNameDetection/TagNameDetection/ViewController.swift b/TagNameDetection/TagNameDetection/ViewController.swift index 23f1716..4724a06 100644 --- a/TagNameDetection/TagNameDetection/ViewController.swift +++ b/TagNameDetection/TagNameDetection/ViewController.swift @@ -9,7 +9,7 @@ import UIKit -class ViewController: UIViewController , UITextViewDelegate { +class ViewController: UIViewController { @IBOutlet weak var txtMain: DPTagTextView! @IBOutlet weak var tbl: UITableView! @IBOutlet weak var lbl: UILabel! @@ -47,16 +47,14 @@ class ViewController: UIViewController , UITextViewDelegate { // self.txtMain.setTxt(str) } -// txtMain.setDelegateToTextView() - self.txtMain.delegate = self +// txtMain.setDelegateToTextView() // If you don't want to use delegate in your class + self.txtMain.delegate = self // If you want to use delegate in your class, Then retrun txtMain.textView(textView, shouldChangeTextIn: range, replacementText: text) in shouldChangeTextIn delegate method. self.txtMain.dpTagDelegate = self tbl.register(UITableViewCell.self, forCellReuseIdentifier: "cell") tbl.isHidden = true // Do any additional setup after loading the view, typically from a nib. } - func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { - return txtMain.textView(textView, shouldChangeTextIn: range, replacementText: text) - } + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. @@ -76,6 +74,12 @@ class ViewController: UIViewController , UITextViewDelegate { } } // MARK:- DPTagTextViewDelegate +extension ViewController : UITextViewDelegate { + func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { + return txtMain.textView(textView, shouldChangeTextIn: range, replacementText: text) // Required for functionality to work. + } +} +// MARK:- DPTagTextViewDelegate extension ViewController : DPTagTextViewDelegate { func tagSearchString(_ str: String) { if (str.count == 0) {