This is a migrated thread and some comments may be shown as answers.

AutoCompleteTextView within UITableViewCell automatic scrolling

4 Answers 35 Views
AutoCompleteTextView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 23 Aug 2016, 05:38 PM
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.

4 Answers, 1 is accepted

Sort by
0
Sophi
Telerik team
answered on 29 Aug 2016, 10:29 AM
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
0
Ryan
Top achievements
Rank 1
answered on 30 Aug 2016, 09:53 PM
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.
0
Ryan
Top achievements
Rank 1
answered on 30 Aug 2016, 09:54 PM
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.
0
Sophi
Telerik team
answered on 01 Sep 2016, 07:49 AM
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
Tags
AutoCompleteTextView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Sophi
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or