我在下面的方法中的行[array removeObjectsInArray:toRemove];
中有例外,无法理解它的错误..
- (void) handleDearchForTerm:(NSString *)searchTerm
{
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];
for (NSString *key in _keys)
{
NSMutableArray *array = [_names valueForKey:key];
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (NSString *name in array)
{
if ([name rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location == NSNotFound)
[toRemove addObject:name];
}
if ([array count] == [toRemove count])
[sectionsToRemove addObject:key];
[array removeObjectsInArray:toRemove];
}
[_keys removeObjectsInArray:sectionsToRemove];
[_table reloadData];
}
答案 0 :(得分:3)
可能数组只是NSArray
的实例,而不是NSMutableArray
的实例,您应该检查_names setObject:forKeys:
答案 1 :(得分:1)
变化:
NSMutableArray *array = [_names valueForKey:key];
要:
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[_names valueForKey:key]];
或者:
NSMutableArray *array = [[_names valueForKey:key] mutableCopy];