NSMutableArray *tempArray = [NSMutableArray arrayWithObjects:@"bat man",@"bat and ball",@"ball", nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] 'bat'"];
NSArray *result = [tempArray filteredArrayUsingPredicate:predicate];
result
массив будет содержащий отфильтрованные объекты, оттуда вы можете получить индекс как:
[ tempArray indexOfObject:/объект из массива результатов один за другим /]
contains[c]
означает, что поиск будет нечувствительным к регистру. Более подробную информацию по предикатам: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html
EDIT
установить делегат текстовое поле в качестве собственной личности. До этого перейдите в YourFile.h, добавьте UITextFieldDelegate
. Теперь в textFieldShouldReturn
сделать это:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
NSMutableArray *tempArray = [NSMutableArray arrayWithObjects:@"bat man",@"bat and ball",@"ball", nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",textField.text];
NSArray *result = [tempArray filteredArrayUsingPredicate:predicate];
return YES;
}
Попробуйте что-нибудь с tableSearch: https://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html –