我有一个UITableView填充从JSON数据饲料使用NSDictionary和NSArray,我试图使用此代码搜索UITableView数据,但它不工作一些其他相关的信息基于我如何设置它是在这个问题Data from JSON Parsing straight to UITableView搜索UITableView
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
// Update the filtered array based on the search text and scope.
// Remove all objects from the filtered search array
[self.filteredCandyArray removeAllObjects];
// Filter the array using NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchText];
NSArray *tempArray = [airportsArray filteredArrayUsingPredicate:predicate];
NSLog(@" text %@", searchText);
filteredCandyArray = [NSMutableArray arrayWithArray:tempArray];
NSLog(@"NSLog %@", scope);
} 这是数据如何解析
NSString* path = @"https://api.flightstats.com/flex/airports/rest/v1/json/active?appId=532ca6af&appKey=50d6d3351e5953152b2688f10d10d276";
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if(nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSMutableDictionary* json = nil;
if(nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
else
{
routeRes = [json objectForKey:@"airports"];
airportsArray = [json objectForKey:@"airports"];
}
_connectionData = nil;
NSLog(@"connection done");
}
NSLog(@" end array %@", candyArray);
// Initialize the filteredCandyArray with a capacity equal to the candyArray's capacity
filteredCandyArray = [NSMutableArray arrayWithCapacity:[airportsArray count]];
// Reload the table
[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
[[self tableView] reloadData];
了我的头顶,我可以告诉你如何不使用谓词而是一个循环的滤镜阵列,如果你不介意......但如果你是然后你需要给我6小时才能完成回家XD –
我没有设置任何方法,如果你有更好的方法我打开建议 – user1828081
我张贴了一个答案与我的想法:3告诉我如果那工作 –