Git Product home page Git Product logo

uitextfield_autosuggestion's Introduction

UITextField_AutoSuggestion

[CI Status](https://travis-ci.org/Kassymov Shyngys/UITextField_AutoSuggestion) Version License Platform

Final auto suggestion feature

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Xcode >= 7
  • iOS >= 8.0

Installation

UITextField_AutoSuggestion is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "UITextField_AutoSuggestion"

Usage

You can use library this way:

  1. Conform to UITextFieldAutoSuggestionDataSource:

    @interface ViewController () <UITextFieldAutoSuggestionDataSource>
  2. Set data source to some UITextField and start observing changes

    // `fieldIdentifier` is optional
    self.textField.autoSuggestionDataSource = self;
    self.textField.fieldIdentifier = @"FIELD_ID";
    [self.textField observeTextFieldChanges];
  3. Implement required data source methods

    #pragma mark - UITextFieldAutoSuggestionDataSource
    
    - (UITableViewCell *)autoSuggestionField:(UITextField *)field tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath forText:(NSString *)text {
        static NSString *cellIdentifier = @"AutoSuggestionCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        
        // configure cell
        cell.textLabel.text = DATA[indexPath.row];
        
        return cell;
    }
    
    - (NSInteger)autoSuggestionField:(UITextField *)field tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section forText:(NSString *)text {
        return DATA.count;
    }
  4. Implement optional data source methods if needed

    - (void)autoSuggestionField:(UITextField *)field textChanged:(NSString *)text {
    	// can be useful in some scenarious, see example project
        [self loadDataFromInternet];
    }
    
    - (CGFloat)autoSuggestionField:(UITextField *)field tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath forText:(NSString *)text {
        return 50;
    }
    
    - (void)autoSuggestionField:(UITextField *)field tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath forText:(NSString *)text {    	    
    	// do something if suggestion row selected
    	NSLog(@"%@", DATA[indexPath.row]);
    }

Author

Kassymov Shyngys, [email protected]

License

UITextField_AutoSuggestion is available under the MIT license. See the LICENSE file for more info.

uitextfield_autosuggestion's People

Contributors

chika-kasymov avatar

Stargazers

MohsinAli avatar

Watchers

James Cloos avatar MohsinAli avatar  avatar

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.