txtSearch.returnKeyType = UIReturnKeyDone;
txtSearch.autocorrectionType = UITextAutocorrectionTypeNo;
[txtSearch addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
-(void)textFieldDidChange:(UITextField *)txtFld {
NSString * match = txtFld.text;
NSArray *listFiles = [[NSMutableArray alloc] init];
NSPredicate *sPredicate = [NSPredicate predicateWithFormat:
@"SELF CONTAINS[cd] %@", match];
listFiles = [NSArray arrayWithArray:[[arrGetTask valueForKey:@"task_name"]
filteredArrayUsingPredicate:sPredicate]];
// Now if you want to sort search results Array
//Sorting NSArray having NSString as objects
NSString *strFilter = [match substringFromIndex:0];
NSLog(@"%@",strFilter);
if ([strFilter isEqualToString:@"#"]) {
arrFilter = nil;
}
else{
arrFilter = [[NSMutableArray alloc]initWithArray: [listFiles
sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];
}
NSLog(@"%@",arrFilter);
[tblView reloadData];
//Use sorted array as your Table’s data source
// -make your table unhidden: yourTbl.hidden = FALSE;
// - reload your table : [yourTbl reloadData];
}
No comments:
Post a Comment