I have a textfield in which whenever user type it shows related items from array in tableView
to select any of them but when user type anything in small keyword it does not show the array. when user enter any word in capital letters as store in an array it shows the array.
i want that when user enter any word whether in small or capital letter it should show the table view containing array. Following is my code,
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSLog(@"Range:%@",NSStringFromRange(range));
NSLog(@"%@",textField.text);
NSString *passcode = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSLog(@"%@",passcode);
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF CONTAINS %@",passcode];
carArray = [_staticCarArray filteredArrayUsingPredicate:predicate];
city = [_staticCarArrays filteredArrayUsingPredicate:predicate];
NSLog(@"%@", carArray);
NSLog(@"%@", city);
if ([carArray count]==0) {
_carTable.hidden = TRUE;
}else{
_carTable.hidden = FALSE;
}
if ([city count]==0) {
_autotable.hidden = TRUE;
}else{
_autotable.hidden = FALSE;
}
[_carTable reloadData];
[_autotable reloadData];
return TRUE;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…