SearchTextField icon indicating copy to clipboard operation
SearchTextField copied to clipboard

itemSelectionHandler is not working

Open PLSV opened this issue 6 years ago • 4 comments

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)
            }
        }

img_0715 img_0716

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
        }

img_0717 img_0718

Can you help me out. How do I solve this problem. Where am I supposed to initialize the SearchTextFieldObject?

PLSV avatar Jun 08 '18 07:06 PLSV

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 avatar Sep 12 '18 20:09 xelz

xelz you give me the answer thankyou

MateoDev97 avatar Jan 30 '19 23:01 MateoDev97

@xelz thanks!

nkark avatar Feb 21 '19 22:02 nkark

@xelz you saved me. Thanks!

trinhtranduc avatar Jun 30 '21 08:06 trinhtranduc