Đây là cách bạn có thể làm điều đó bằng NSPredicate
Bạn có thể thử một cái gì đó như thế này trong các đại biểu UITextView:
- (void)textViewDidChange:(UITextView *)textView
{
_words = [self.textView.text componentsSeparatedByString:@" "];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[cd] '@'"];
NSArray* names = [_words filteredArrayUsingPredicate:predicate];
if (_oldArray)
{
NSMutableSet* set1 = [NSMutableSet setWithArray:names];
NSMutableSet* set2 = [NSMutableSet setWithArray:_oldArray];
[set1 minusSet:set2];
if (set1.count > 0)
NSLog(@"Results %@", set1);
}
_oldArray = [[NSArray alloc] initWithArray:names];
}
nơi _words, _searchResults và _oldArray là NSArrays.
làm bạn cần để có được những nhân vật trong chỉnh sửa hoặc sau khi chỉnh sửa (có thể bằng cách gọi một hành động)? theo thời điểm này tôi có thể giúp bạn – ilhnctn