-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selection from the autocomplete always returns the first value and not the actual selected value #23
Comments
I have this problem too, did you solve it? |
Modifying the plugin was a bit tedious. I found a much better and simple way of doing this. Please refer to the link below. Just copy and paste the answer in the comments and it works like a charm. http://stackoverflow.com/questions/26885438/getting-autocomplete-to-work-in-swift Hope this helps. |
Yes, but i need it as dropdown :( |
Is this table that hide and show? |
Do i need to add tableview in storyboard? |
Yes it's a tableview that shows and hides. Yes add it in the storyboard and set the datasource and delegate and it should work! |
Ohh, i tried without adding tableview to storyboard.. |
Also link the tableview to an IBOutlet if you want it to dismiss when the view ends editing. |
How to hide tableveiw when done editing? |
Create an IBOutlet for the tableview and then in the didSelectRowAtIndexPath function make the changes below func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedCell : UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
textField.text = selectedCell.textLabel!.text
tableview.hidden = true
} |
I did that, but i now i have problem when i touch outsite textfield, to hide tableview and close keyboard? |
Simple. Add this code in your view controller override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
tableView.hidden = true
} |
Thanks, it works great.. |
Couple of tweaks to make it work with Swift 2.0 in case anyone else reads this. Add a class var called "selectedText", and make these three changes: At the beginning of layoutSubviews, clear out the selectedText class var: override func layoutSubviews(){
super.layoutSubviews()
let str : String = self.text!
if (str.characters.count > 0) && (self.isFirstResponder())
{
if (mDelegate != nil){
self.selectedText = nil Set selectedText in the didSelectRowAtIndexPath func before you resign first responder: self.selectedText = self.applyFilterWithSearchQuery(self.text!)[indexPath.row]["DisplayText"] as? String Finally update the handleExit method: //Swift 2.0 compatible
func handleExit(){
...
if ((mDelegate?.textFieldShouldSelect?(self)) != nil){
if (self.applyFilterWithSearchQuery(self.text!).count > 0) && (mDelegate?.textFieldShouldSelect!(self).boolValue == true) && (self.selectedText == nil){
...
else{
if let finalText = self.selectedText {
self.text = finalText
mDelegate?.textFieldDidEndEditing?(self, withSelection: ["DisplayText":finalText])
} else {
mDelegate?.textFieldDidEndEditing?(self, withSelection: ["DisplayText":self.text!, "CustomObject":"NEW"])
}
}
}
} |
Is there a way to return the tableview selected index value?
The text was updated successfully, but these errors were encountered: