Category for UITextField to add auto suggestion feature. [Tutorial](http://shyngys.com/uitextfield_and_auto_suggestion).
Switch branches/tags
Nothing to show
Clone or download
Latest commit 809febf Apr 8, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Version bump Apr 8, 2018
UITextField_AutoSuggestion Empty view fix Apr 8, 2018
.gitignore Initial commit Jan 29, 2017
.travis.yml Edited .travis.yml to avoid warnings Feb 1, 2017
LICENSE Initial commit Jan 29, 2017
README.md Increased version to 0.2.0 Feb 9, 2017
UITextField_AutoSuggestion.podspec Version bump Apr 8, 2018
_Pods.xcodeproj Initial commit Jan 29, 2017
auto_suggestion.gif Edited pod info and README Jan 31, 2017

README.md

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, chika.kasymov@gmail.com

License

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