我试图在表格视图中搜索数据......
-(void)searchTableView{
NSString *searchText=searchBar.text;
NSMutableArray *searchArray=[[NSMutableArray alloc]init];
// for (NSDictionary *dictionary in djList) {
// NSLog(@"NSDictionary value is%@",dictionary);
//// NSArray *array = [dictionary objectForKey:@""];
//// [searchArray addObjectsFromArray:array];
// }
for (NSString *sTemp in searchArray) {
NSRange titleResultsRange=[sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length>0) {
[copyListArray addObject:sTemp];
}
}
[searchArray release];
searchArray=nil;
}
我的注释行有问题......
我不知道如何处理ObjectForkKey:@“”;
有没有其他方法可以解决这个问题......没有使用NSDictionary ....
@thanks提前。
答案 0 :(得分:1)
使用NSPredicate
NSPredicate *annotationPredicate = [NSPredicate predicateWithFormat:@"(Latitudine = %@)AND(Longitudine = %@)AND(Name = %@) ",latitudeString,longitudeString,name];
SMutableArray *myArray = [[NSMutableArray alloc] initWithArray:sourceArray];
[myArray filterUsingPredicate:annotationPredicate];
数组中的字典必须具有数组中的键,在这种情况下为“Latitudine”,“Longitudine”,“Name”。
NSpredicate doc here。并查看那里的示例代码。
查看NSMutableArray doc
- (void)filterUsingPredicate:(NSPredicate *)predicate
答案 1 :(得分:0)
-(void)searchTableView{
NSString *searchText=searchBar.text;
NSMutableArray *searchArray=[[NSMutableArray alloc]init];
// for (NSDictionary *dictionary in djList) {
// NSLog(@"NSDictionary value is%@",dictionary);
//// NSArray *array = [dictionary objectForKey:@""];
//// [searchArray addObjectsFromArray:array];
// }
[searchArray addObject:@"Alexandro"];
[searchArray addObject:@"Beatzz"];
[searchArray addObject:@"Cat"];
[searchArray addObject:@"Chucky"];
[searchArray addObject:@"DJ Cat"];
[searchArray addObject:@"DJ Kuiken"];
[searchArray addObject:@"Dj Michel"];
[searchArray addObject:@"Dj Navarro"];
[searchArray addObject:@"Dj Peter"];
[searchArray addObject:@"Dj Wily - Waxfiend"];
[searchArray addObject:@"Himself"];
[searchArray addObject:@"janery - Chucky - Waxfiend"];
for (NSString *sTemp in searchArray) {
NSRange titleResultsRange=[sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length>0) {
[copyListArray addObject:sTemp];
}
}
[searchArray release];
searchArray=nil;
}`enter code here`
它静态添加其工作正常...............
相同的addobjects在我的djlist数组中......这是nsmutableArray ....
所以我直接添加了searchArray = djlist ......它变得丑陋了。崩溃......