nicklockwood / FXForms

[DEPRECATED]
Other
2.93k stars 339 forks source link

Search bar / filter for long options list #281

Open ivanharmat opened 9 years ago

ivanharmat commented 9 years ago

I would like to build a search filter like this for your form helper: ios simulator screen shot dec 31 2014 3 38 57 pm

It would be very useful for long lists, if you don't want to scroll down, you just type first 2-3 letters. I don't think this functionality is possible with the current version, although your form helper is very versatile. Could you point me in the right direction how to do this? I would just instantiate the search bar like so:

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
self.searchBar.placeholder = @"Filter";
self.tableView.tableHeaderView = self.searchBar;

But it will have to be optional, bar tint color, placeholder, and other settings editable. I would create a pull request if this functionality is demanded by others. Thanks.

wdcurry commented 9 years ago

I have not had time to get this to work properly yet, but this repo provides all the base required, just needed integration into fxforms:

https://github.com/EddyBorja/MLPAutoCompleteTextField

ivanharmat commented 9 years ago

@wdcurry looks pretty good. I'll look into that. Thanks

billguy commented 9 years ago

I achieved this by implementing a custom view controller with FXFormFieldViewController that used UISearchController. I also had to do:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (self.searchController.isActive) {
        Customer *selectedCustomer = [self.resultsFilteredTableController.filteredResults objectAtIndex: indexPath.row];
        indexPath = [NSIndexPath indexPathForRow:[[Customer list] indexOfObject:selectedCustomer] inSection:0];
    }
    UITableViewCell<FXFormFieldCell> *cell = (UITableViewCell<FXFormFieldCell> *)[self.formController.tableView cellForRowAtIndexPath:indexPath];
    if ([cell respondsToSelector:@selector(didSelectWithTableView:controller:)]) {
        [cell didSelectWithTableView:tableView controller:self];
    }
}

to get the selected row from the filtered results.

ivanharmat commented 9 years ago

@billguy I'm going to try this solution, too. Thanks