Giter VIP home page Giter VIP logo

autocompletetextfieldswift's Introduction

AutocompleteTextfieldSwift

Simple and straightforward sublass of UITextfield to manage string suggestions

Plain Attributed
Plain Attributed

Installation

Drag AutoCompleteTextField Folder in your project

How to use

Customize

Customize autocomplete suggestions! You can override the provided properties to create your desired appearance. Properties are pretty self explanatory. Some of them are listed below, with their respective default values:

/// Font for the text suggestions
public var autoCompleteTextFont = UIFont(name: "HelveticaNeue-Light", size: 12)
/// When set to true, shows autocomplete text with formatting
public var enableAttributedText = false
/// User Defined Attributes
public var autoCompleteAttributes:[String:AnyObject]?
/// Hides autocomplete tableview after selecting a suggestion
public var hidesWhenSelected = true

Setting Content

The most important property to use is the autoCompleteStrings. As what is declared in the description setting the value of this will automatically reload the tableview, through the use of didSet

/// The strings to be shown on as suggestions, setting the value of this automatically reload the tableview
public var autoCompleteStrings:[String]?{
   didSet{ reload() }
}

User Interactions

To handle text changed event, use onTextChange: closure. This returns the current text content of the textfield.

autocompleteTextfield.onTextChange = {[weak self] text in 
// your code goes here
...
}

To know when user selected a text, use onSelect: closure: This returns the selected text and it's indexPath.

autocompleteTextfield.onSelect = {[weak self] text, indexpath in
// your code goes here
...
}

It's that easy! Feel free to use it, don't worry, it's free. :)

Example Code:

In the example project, I used Google Places Autocomplete API to show the usage of this library. For testing purposes i created my own google api key.

If you want to create your own Google Api Key follow the steps in this link

Note: Recent updates in google places API requires you to enable "Google Places API Web Service" and use a Server Key instead of an iOS key. To do so, go to Google Developers Console.

License

AutocompleteTextfield is under MIT license. See LICENSE for details.

autocompletetextfieldswift's People

Contributors

chug2k avatar jkereako avatar mnbayan avatar nekflamm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autocompletetextfieldswift's Issues

Clinking 2nd or 3rd item in dropdown table doesn't call onSelect

I have a signup form and I am using this AutocompleteTextfield. But when I click on 2nd or 3rd Item, onSelect is not called, it is only called for 1st Item click.

I am guessing, I am seeing this issue because behind 2nd and 3rd item, I have my own fields.

newSuperView ni pointer - semi-resolved issue

Changed this line as once the parent viewController was dismissed a nil pointer error was being thrown after returning to the previous viewController.

While the fix works i'm not sure as to what is the underlying issue.

open override func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
commonInit()
//Changed this
if (newSuperview != nil){
setupAutocompleteTable(newSuperview!)
}
}

Wrong place into the frame

The function setupAutocompleteTable is not calculating the right place.
I pass a subview that is into a subview, and the frame is calculated improperly, I had to overwrite the function in order to fix this issue.

Is there an update to that fix? If not when I finish I will submit my solution.

Tableview doesn't show

Hi,

I integrated your project and I can't seem to get it to work.
My tableview doesn't show up. I created only a textfield in my storyboard
and i'm getting response from my google places api but the tableview just doesn't show up.
You have any idea if you have to do something special that isn't included in your project to get it to work?

Thanks in advance!

Only 3 suggestions no matter what

I configured the Plugin as u showed in the ViewController and set this autocompleteTextfield.maximumAutoCompleteCount = 20 but always get just the first 3 results of my response array shown. Any Idea?
bildschirmfoto 2016-07-09 um 18 28 52

subclass into uiview

Hello!

  1. subclass autocompletetextfield in uiview class
  2. use no nib, just instantiate and use from the frame
  3. voila table unresponsive and cant select values; although can type and return result<STILL TABLE UNRESPONSive; meaning cant click or do anything.. >

any help?

didSelectRowAtIndexPath never called

didSelectRowAtIndexPath is never called.
As per the previous issue #19 i check my code it doesnt contain this method also
public override func resignFirstResponder() -> Bool {
self.autoCompleteTableView?.hidden = true

return super.resignFirstResponder()

}

can you please let me know the issue

autocomplete in container

Hello

the autocomplete is in a small container so... when i select a row it doesn't work

If i have more Height of the container it's works (but i want a small container:)

i try

view.bringSubviewToFront(tableView)
don't work

someone have an idea ?

regards

XCode 8/Swift 3 Problems

The TableView never appears. I have debugged showing events firing correctly, but I never see any results appear after calling .autoCompleteStrings. Has anyone had any success after upgrading to xCode 8?

putting the textView inside a stackView.

when i put the text view inside a stackview, the autoCompleteTableView stopped responding to scrolls and selections even though it showed up on the screen. loks like it could not get the focus.

How to use with Auto Layout ?

So I wanted to use AutocompleteTextfieldSwift in my project, but I use Autolayout in my Main.storyboard.

I wanted to know how the TableView for results can be below the textfield. Please see the screenshot attached (I set autoCompleteTableHeight to 200.0 in this exemple)

image

Thanks

How to implement to other project?

private func handleTextFieldInterfaces(){
    location.onTextChange = {[weak self] text in
        if !text.isEmpty{
            if let dataTask = self?.dataTask {
                dataTask.cancel()
            }
            self?.fetchAutocompletePlaces(text)
        }
    }

    location.onSelect = {[weak self] text, indexpath in
        Location.geocodeAddressString(text, completion: { (placemark, error) -> Void in
            if let coordinate = placemark?.location?.coordinate {
                self?.addAnnotation(coordinate, address: text)
                self?.mapkit.setCenterCoordinate(coordinate,  animated: true)
            }
        })
    }
}

i facing problem for on textchange

How to set place type to "Address"??

I am using swift 3.2, predictions are giving Countries and cities name instead of a proper address. How can I get the only complete address in predictions??

best way to hide keyboard?

i've had a gesture recognizer that when tapped anywhere on screen it removed the keyboard and stopped the editing, now it doesn't work with this library, if used i can't select the tableview autocomplete suggestions, now i'm calling the 'resignFirstResponder' when 'return' is clicked, is there a better solution? i really liked how the gesture recognizer worked, is there any workaround to make it work?

EXC_BAD_ACCESS when trying to use any property

I'm trying to use properties such as autoCompleteStrings and onTextChange with my AutoCompleteTextField, but every time the app runs, it crashes and gives me an EXC_BAD_ACCESS error code. I can't figure out why. The app runs perfectly if I don't set any properties. Any ideas?

Superview not available (TableView not showing)

Not sure if it's the same problem #2 has, but I thought I'll write this down in case you want to take a look or if somebody else runs into this.
I'm manually adding the view, so I'm using the initWithFrame method which then internally calls initialize (and setupTableView). The problem is that inside setupTableView you're adding the table view to the field's superview. But I'm obviously adding the field to my super view after the init call. Probably when using Storyboards the superview is already ready at that point.

Thanks anyway for your work, it's looking great in my project :)

dismiss keyboard

is there an inbuilt function in the autocomplete class to dismiss the keyboard?

Tableview comes up but is blank

I start typing and the tableview pops up like expected but it's blank. here are the func's I'm using
swift 3
xcode 8
`

 func configureTextFields(){
    employeeNameTextField.autoCompleteTextColor = UIColor.black
    employeeNameTextField.autoCompleteTextFont = UIFont.systemFont(ofSize: 14.0)
    employeeNameTextField.autoCompleteCellHeight = 35.0
    employeeNameTextField.maximumAutoCompleteCount = 20
    employeeNameTextField.hidesWhenSelected = true
    employeeNameTextField.hidesWhenEmpty = true
    employeeNameTextField.enableAttributedText = true
    var attributes = [String:AnyObject]()
    attributes[NSForegroundColorAttributeName] = UIColor.black
    attributes[NSFontAttributeName] = UIFont(name: "HelveticaNeue-Bold", size: 12.0)
    employeeNameTextField.autoCompleteAttributes = attributes
}

func handleTextFieldInterfaces(){
    employeeNameTextField.onTextChange = {[weak self] text in
        if !text.isEmpty{
            self?.employeeNameTextField.autoCompleteStrings = ["jay", "jason", "josh", "john", "jill", "jimmy", "jim"]
        }
    }
    
    employeeNameTextField.onSelect = {[weak self] text, indexpath in
        print(text)
    }

}`

any thoughts?

Showing autocomplete table after uitextfield is pre-filled

Hi, At the moment, a keypress needs to happen in order for the uitextfield to send a request to fetch and display the autocomplete data, but I'm just looking to see if there's a way to show the autocomplete table with the uitextfield text value pre-defined programmatically. It will be great if you could shed me some light on this. Thanks.

Great framework, thank you so much for your contribution :)

Multiple TextFields.

Greate component. I have a small problem.

Lets say I have 3 textfields I'm populating with autoCompleteStrings = [String]. And on textchange everything works as it should.

But I also have 2 textFields I would like the tableview to function as a "picker" instead. So when the specific textField becomeFirstResponder i would like to populate the tableView with strings and the one on [String][0] should be pre-filled in the textField.

Edit: I can't seem to hide one textFields tableView when another textField becomeFirstResponer

Does it make sense?

Pre-Salamat, ;)

fatal error: unexpectedly found nil while unwrapping an Optional value

Hi there!
What a great add on to the Xcode Swift Community!

I am a beginner programmer, so I really don't know why things do the things they do. Especially in Swift, since I am just starting to learn it.

Anyways, I just wanted to let you know, I don't know if this is a bug or not, but I ran into an issue using your plugin.

I embedded a navigation controller to eventually reach the view that implements your autocomplete plugin, and when i hit "back" it brings up a fatal error, saying that it unexpectedly found nil while unwrapping an optional value.

The line of code where it crashes is line 77 for me: setupAutocompleteTable(newSuperview!)
inside the public override func willMoveToSuperview(newSuperview: UIView?)

anyways, not sure if you wanted to try that out and take a look at it, it could also be just me that I may have added some things and didn't realize.

using a stackview

when i put the text view inside a stackview, the autoCompleteTableView stopped responding to scrolls and selections even though it showed up on the screen. loks like it could not get the focus.

didSelectRowAtIndexPath event fires after long press When embedded in UIScrollview

When i use AutoCompleteTextField inside in a uiscrollview the didSelectRowAtIndexPath that calls onSelect gets fired after long press..

So i tried this........................... [(http://stackoverflow.com/questions/38217789/didselectrowatindexpath-called-after-long-press...............................)] also which seems to create the same problem.

Unknown class AutoCompleteTextField in Interface Builder file.

I am getting error:

Unknown class AutoCompleteTextField in Interface Builder file.

I don't know why this is happening, but this line is making this problem:

destinationAddressLabel.onTextChange = {[weak self] text in
...

I added AutocompleteTextfield.swift to Compile Sources.
Any solution?

How to assign this textfield to my tableviewcell Textfield

I am using Swift 3, and I have tableview class, inside that, I have textfield class. I tried to add this textfield, but getting crashed in following line

        setupAutocompleteTable(superview!)

and showing superview as nil

can you help me to solve this issue.

Rotation to landscape issue

When the autocomplete tableView is showing with its autocomplete-suggestions and you rotate to landscape, the tableView won't redraw which leads to separator lines that only fill half of the screen width instead of the new screen width from landscape screen.

I wrote a quick workaround, exposing redrawTable in AutoCompleteTextField.swift:

func redrawTable() {

        if let autoCompleteTableView = autoCompleteTableView,

           let autoCompleteTableHeight = autoCompleteTableHeight  {

            var newFrame = autoCompleteTableView.frame

            newFrame.size.height = autoCompleteTableHeight

            let screenSize = UIScreen.mainScreen().bounds.size

            newFrame.size.width = screenSize.width - (self.frame.origin.x * 2)

            autoCompleteTableView.frame = newFrame

        }
}

Then in your ViewController you can do sth like this:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {

    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    coordinator.animateAlongsideTransition(nil, completion: { _ in

        self.autoCompleteTextField.redrawTable()

    })
}

Complete in text field

Instead of making a table for the suggestions, how would I make them just appear in the text view as you type.

fatal error: unexpectedly found nil while unwrapping an Optional value

Hey, I tried using your code for my application. Unfortunately when I click on button and the viewcontroller appears modally with navigation controller embedded in, it show the following error in AutocompleteTextfield.

fatal error: unexpectedly found nil while unwrapping an Optional value

The error occurs at following function:

public override func awakeFromNib() {
super.awakeFromNib()
commonInit()
setupAutocompleteTable(superview!)

Swift 2.0

Please update for Swift 2.0 support <3

Tableview not scrolling

I have integrated all properties of AutocompleteTextfieldSwift, and dropdown is working fine. But i can't scroll or select any row of tableview(dropdown)

Text doesn't autocomplete?

I've implemented all that is required from this great add on, but for some reason, though the "autoCompleteStrings" appear in the table view for the text field, it doesn't actually autocomplete when I begin typing. is there a problem with my handleTextFieldInterfaces?

`private func handleTextFieldInterfaces()
{
self.chemicalAuto.onTextChange = {[weak self] text in

        print("Change")
        var keys = Array(DataSource.sharedManager.chemicalTable.keys)
        self!.chemicalAuto.autoCompleteStrings = keys
}

    self.chemicalAuto.onSelect =
    {
        [weak self] text, indexpath in

        print("select")
        var keys = Array(DataSource.sharedManager.chemicalTable.keys)
        self!.chemicalAuto.autoCompleteStrings = keys
    }
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.