AutoCompleteTextView within UITableViewCell automatic scrolling

5 posts, 0 answers
  1. Ryan
    Ryan avatar
    25 posts
    Member since:
    Jun 2016

    Posted 23 Aug Link to this post

    UITableViewController automatically scrolls to UITextFields within UITableViewCells. This works for cells in which I have normal UITextFields however it does not work with the AutoCompleteTextView which has a UITextField inside a TKView. How can I make this automatic scrolling functionality work for AutoCompleteTextView? I got it working if I scrolled to it manually with the UIKeyboardWillShowNotification but I do not want to accomplish it this way because it will conflict with other code I have for next/previous buttons that scrolls to the next/previous text field.
  2. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 29 Aug Link to this post

    Hello Ryan,

    The scenario you are describing is a bit specific so it will be a great time saver if you are able to send us a sample project showing the issue. This way we can examine the project and provide a possible solution, which suites your scenario, in short terms.

    Thank you for your cooperation.

    Regards,
    Sophi
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Ryan
    Ryan avatar
    25 posts
    Member since:
    Jun 2016

    Posted 30 Aug in reply to Sophi Link to this post

    Unfortunately I cannot provide my source code. It is pretty easily to replicate. Just add TKAutoCompleteTextView to the content view of several UITableViewCells until the table has enough cells so that the keyboard covers the autocomplete field when it is clicked on and notice that it will not automatically scroll as is the standard iOS behavior for UITableViewController.
  5. Ryan
    Ryan avatar
    25 posts
    Member since:
    Jun 2016

    Posted 30 Aug in reply to Ryan Link to this post

    This is a standard iOS feature for UITableViewController that is supposed to work for all UITextFields, which is what TKAutoCompleteTextView has inside of its view.
  6. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 01 Sep Link to this post

    Hi Ryan,

    We have tried to reproduce the described behavior but UITableViewController seems to work fine with the TKAutoCompleteTextView. The scroll feature is presented both with UITextField and TKAutoCompleteTextView.

    The approach I went with is creating a custom cell, derived from UITableViewCell, which has a TKAutoCompleteTextView as a subview. Look the snippet below.
    @implementation AutoCmpCell{
         
        TKDataSource *_dataSource;
    }
     
    -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self){
            self.autocmp = [[TKAutoCompleteTextView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 30)];
            NSArray *sampleArrayOfStrings =@[@"Kristina Wolfe",@"Freda Curtis",@"Jeffery Francis",@"Eva Lawson", @"Theresa Bryan", @"Jenny Fuller", @"Terrell Norris", @"Eric Wheeler", @"Julius Clayton", @"Alfredo Thornton", @"Roberto Romero",@"Orlando Mathis",@"Eduardo Thomas",@"Harry Douglas"];
     
            _dataSource = [[TKDataSource alloc] initWithArray:sampleArrayOfStrings];
            [_dataSource.settings.autocomplete createToken:^TKAutoCompleteToken *(NSUInteger dataIndex, id item) {
                TKAutoCompleteToken *token = [[TKAutoCompleteToken alloc] initWithText:item];
                return token;
            }];
            self.autocmp.dataSource = _dataSource;
            self.autocmp.backgroundColor = [UIColor purpleColor];
            self.autocmp.displayMode = TKAutoCompleteDisplayModePlain;
            self.autocmp.suggestMode = TKAutoCompleteSuggestModeAppend;
             
            [self.contentView addSubview:_autocmp];
        }
         
        return self;
    }

    Then in the UITableViewController I am using my custom cell instead of the default UITableViewCell.
    @implementation ViewController
     
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor whiteColor];
        self.tableView.dataSource = self;
        [self.tableView registerClass:[AutoCmpCell class]  forCellReuseIdentifier:@"cell"];
    }
     
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        UITableViewCell *c = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        c.backgroundColor = [UIColor yellowColor];
        return c;
    }
     
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return 1;
    }
     
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 30;
    }
     
    @end

    In case these snippets do not work on your machine, would you confirm that you are using 2016.1.504 version of TelerikUI? 

    Regards,
    Sophi
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner