SearchTextField
SearchTextField copied to clipboard
itemSelectionHandler is not working
I am using this cocoapod for iOS swift 3 i.e v(1.0.2). I have used this pod for my project and it works well when I use it in my self made modal, but when I try to use it in a normal view in my app, it does not seem to work at all. What is going on here?
This is the example of my self made modal using the autocomplete feature. On choosing from the list you can see that a couple of tags are added Code for the modal view :
breedSearchTextField = SearchTextField()
breedSearchTextField.itemSelectionHandler = { (item) in
if !self.selectedBreeds.contains(item.title) {
self.selectedBreeds.append(item.title)
var tag = self.breedListView.addTag(item.title)
tag.backgroundColor = UIColor(red: 235/255, green: 235/255, blue: 235/255, alpha: 1)
tag.enableRemoveButton = true
self.dialogView.frame.size = CGSize(width: self.frame.width-50, height: self.dialogView.frame.height+17.5)
}
}
I am trying to do the same for normal views. But nothing is happening. The item selection handler is not responding at all code for normal view :
breedSearchTextField = SearchTextField()
breedSearchTextField.itemSelectionHandler = { (item) in
print("The selected breed is \(item.title)")
self.chosenBreed = item.title
}
Can you help me out. How do I solve this problem. Where am I supposed to initialize the SearchTextFieldObject?
Are you using IQKeyboardManager? Maybe you have enabled IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = true
To make it work, in that view you have to disable like this on viewWillAppear:
IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = false
And enable it again on viewWillDissapear
xelz you give me the answer thankyou
@xelz thanks!
@xelz you saved me. Thanks!