我有一个PickerView
和TableView
并且我将数据从服务器加载到pickerView,一旦我在选择器中选择了城市,我就会在tableView中显示结果。
要做到这一点,我使用NSPredicate
从词典中过滤它并显示结果......但它没有显示任何值。那么请问我的问题在哪里?我做错了吗?
数据要求PickerView
{"Status":1,"Response":[{"ID":19,"Title":"G.A","Name":"G.A"},{"ID":8,"Title":"Mexico","Name":"Mexico"},{"ID":17,"Title":"USA","Name":"USA"},...
数据调用tableView
{"ID":309436,"CountryID":8,"CountryName":"Mexico","Previous":"%3,0","Actual":"%3,0","cast":"%2,9","Event":"M2","Priority":1,"Date":"14.10.2014","Time":"01:50:00"},{"ID":309437,"CountryID":8,"CountryName":"Mexico","Previous":"%2,4","Actual":"%2,5","cast":"%2,4","Event":"M3","Priority":1,"Date":"14.10.2014","Time":"01:50:00"},{"ID":317211,"CountryID":17,"CountryName":"USA","Previous":"%0,1","Actual":"%1,2","cast":"%1,4","Event":"GPS1","Priority":3,"Date":"14.10.2014","Time":"02:00:00"},{"ID":317212,"CountryID":17,"CountryName":"USA","Previous":"%2,4","Actual":"%2,4","cast":"%2,6","Event":"GPS","Priority":3,"Date":"14.10.2014","Time":"02:00:00"},
我想获得Event
和Date
值。
- (void)runURL
NSURL *url = [NSURL URLWithString:@"http://www.example.com.ashx"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *connectionError)
{
if (data.length > 0 && connectionError == nil)
{
dicList2 = [NSJSONSerialization JSONObjectWithData:data
options:0
error:NULL];
if([[[dicList2 objectForKey:@"Success"] stringValue] isEqualToString:@"1"]){
[dataCalendarArray3 addObjectsFromArray:[dicList2 objectForKey:@"Response"]];
}
}
- (void)runPredicate
{
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF.CountryName MATCHES ‘%@‘", @"Mexico"];
NSArray *ar = [dicList2 objectForKey:@"Response"];
NSArray *filter = [ar filteredArrayUsingPredicate:pred];
NSLog(@"New List %@",filter);
}
答案 0 :(得分:0)
试试这个NSPredicate * resultPredicate = [NSPredicate predicateWithFormat:@“SELF包含[cd]%@”,searchText];