I have implemented an autocomplete table, that shows up when the user selects the Model field in my table.
However, I am having issues controlling how it appears. I would ultimately like the Models Cell to scroll up to the top, the autocomplete table to show between it and the keyboard. Nothing I try will cause this table to act in that nature.
In this example the autocomplete table is showing up under the header titles when the user starts to type 'F'
The Autocomplete table is initialized and then hidden. Only when the Model textfield begins editing does it show up.
Here is the code the creates the table.
CGRect frameAuto = CGRectMake(0, self.txt_model.frame.origin.y + self.txt_model.frame.size.height, self.view.frame.size.width, self.txt_model.frame.size.height * 3);
self.autocompleteTableView = [[UITableView alloc] initWithFrame:frameAuto style:UITableViewStylePlain];
self.autocompleteTableView.delegate = self;
self.autocompleteTableView.dataSource = self;
self.autocompleteTableView.scrollEnabled = YES;
self.autocompleteTableView.hidden = YES;
[self.view addSubview:self.autocompleteTableView];
I guess what I am needing help with, is how do I get the Model textfield to move up to the Navigation bar, show the autocomplete table and leave room for the keyboard?
UPDATE -- Adding the autocompletetableview as an accessory view does this:
Creating the autocomplete table
self.autocompleteTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
self.autocompleteTableView.delegate = self;
self.autocompleteTableView.dataSource = self;
self.autocompleteTableView.scrollEnabled = YES;
self.autocompleteTableView.hidden = YES;
[self.view addSubview:self.autocompleteTableView];
Setting the textfield
self.txt_model.delegate = self;
self.txt_model.inputView = self.autocompleteTableView;
self.txt_model.inputAccessoryView = self.autocompleteTableView;
Textfield delegate
-(void)textFieldDidBeginEditing:(UITextField *)sender {
if(sender == self.txt_model){
NSLog(@"Moving view up");
[self.tblDetailsView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
Presents the entire autocompletetable over the the input form.
Keyboard is not present nor the textfield.
To get the effect you are looking for you could try setting it as the inputAccessoryView on the UITextField you are editing. This will stick it directly to the top of the keyboard. I'm not sure how well a UITableView will work as the inputAccessoryView but it might be worth a try.
self.textView.inputAccessoryView = autocompleteTableView