사용자가 필터 문자열을 입력 할 때 UIPicker가 데이터를 필터링하는 간단한 필터 메커니즘을 작성하려고합니다. 나는 거의 일하고있다.iPhone SDK : 필터를 적용한 후 NSMutableArray 데이터 세트를 복원하는 방법은 무엇입니까?
이것은 내 필터 코드이며 작동합니다. 내 질문에, 일단 내가 데이터 소스에 필터를 적용하면, 어떻게 술어를 제거하고 원래의 데이터 세트를 복원 할 수 있습니까? 내 데이터 소스에 NSMutableArray를 사용하고 있습니다.
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'B'"];
[arrayCountryChoices filterUsingPredicate: predicate];
[pickerCountry reloadComponent:0];
감사합니다. 이로 편집
는 방법 나는이 오류를 얻고을 제안했다. * 캐치되지 않은 예외 'NSInvalidArgumentException'으로 인해 앱 종료 중, 이유 : '* - [UIView numberOfComponentsInPickerView :] :
확실하지 않습니다. 이것은 내가 생각할 수있는 모든 관련 코드입니다. 나는 또한 IB에서 나의 연결을 점검했다. 왜 그런가?
//create data
arrayCountryChoices = [NSArray arrayWithObjects:@"foo",@"bar",@"baz",nil];
//copy the original array to searchable array
arraySearchResults = [arrayCountryChoices mutableCopy];
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [arraySearchResults count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arraySearchResults objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//grab the selected country
strUserChoice = [arraySearchResults objectAtIndex:row];
}