【发布时间】:2017-07-07 05:30:05
【问题描述】:
我有一个这种格式的 JSON 字典
{
"382" : "sudhir kumar",
"268" : "David ",
"385" : "aayush test",
"261" : "Mike watson",
"277" : "TestDrivers Driver",
"381" : "sudhir kumar",
"380" : "sudhir kumar",
"383" : "asdfgh asdfgh",
"376" : " "
}
我必须在 UISearchBar 中显示它。有人请帮我解决这个问题,因为当我从搜索中选择任何名称时,它的相应 ID 也已选择
我正在使用以下代码过滤名称,但不过滤其相关 ID 和名称
我的代码是:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;
{
tempArray = [NSArray arrayWithArray:DriverNameArray];
//NSString *stringToSearch = textField.text;
tempId = [NSArray arrayWithArray:DriverIdArray];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@",searchText]; // if you need case sensitive search avoid '[c]' in the predicate
//NSPredicate * predicateid = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@",stringToSearch];
NSArray *tempresults = [DriverNameArray filteredArrayUsingPredicate:predicate];
if (tempresults.count > 0)
{
tempArray = [NSArray arrayWithArray:tempresults];
tempId = [NSArray arrayWithArray:tempresults];
}
[SEarchTable reloadData];
//return YES;
}
【问题讨论】:
-
你试过什么显示你的代码?
-
请检查我更新的问题
标签: ios objective-c json uisearchbar