任何人都可以向我指出任何关于如何创建自动填充文本字段的示例项目或提示,其中用户键入一个通用名称,例如“美国航空公司”,其具有另一个值,例如“AA”(对于美国航空公司)和用户类型根据文本字段中的内容建议结果?
像这样:
任何提示都会很棒!
谢谢大家。
答案 0 :(得分:2)
根据我的经验在IB中添加搜索显示控制器。然后我将代码添加到RootViewController.m中,如下所示:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
NSInteger searchOption = controller.searchBar.selectedScopeButtonIndex;
return [self searchDisplayController:controller shouldReloadTableForSearchString:searchString searchScope:searchOption];
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
NSString* searchString = controller.searchBar.text;
return [self searchDisplayController:controller shouldReloadTableForSearchString:searchString searchScope:searchOption];
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString*)searchString searchScope:(NSInteger)searchOption {
NSPredicate *predicate = nil;
if ([searchString length])
if (searchOption == 0) // full text, in my implementation. Other scope button titles are "Author", "Title"
predicate = [NSPredicate predicateWithFormat:@"title contains[cd] %@ OR author contains[cd] %@", searchString, searchString];
else
// docs say keys are case insensitive, but apparently not so.
predicate = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", [[controller.searchBar.scopeButtonTitles objectAtIndex:searchOption] lowercaseString], searchString];
[fetchedResultsController.fetchRequest setPredicate:predicate];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return YES;
}
This is tutorial for help you.
<强>感谢。 :)强>
答案 1 :(得分:1)
看看我的实施,MLPAutoCompleteTextField。它是开源的。
它可以自动完成,类似于谷歌的即时搜索。它使用Levenshtein Distance算法对条目进行排序。
答案 2 :(得分:0)