Skip to content

Commit

Permalink
Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Datt committed Nov 5, 2019
1 parent 192008f commit daa128d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class DPTagTextView: UITextView , UITextViewDelegate {
func setTxt(_ str:String) {
arrRange = [Range<String.Index>]()
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)") {
Expand Down
16 changes: 10 additions & 6 deletions TagNameDetection/TagNameDetection/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit daa128d

Please sign in to comment.