我可以指出,我为什么在《刑法》中被带往可变物体的突变方法。 阵列必须是不可改变的,但我不知道为什么。
接口:
@interface SectionsViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate> {
UITableView *table;
UISearchBar *search;
NSMutableDictionary *names;
NSMutableArray *keys;
}
@property (nonatomic, retain) IBOutlet UITableView *table;
@property (nonatomic, retain) IBOutlet UISearchBar *search;
@property (nonatomic, retain) NSDictionary *allNames;
@property (nonatomic, retain) NSMutableDictionary *names;
@property (nonatomic, retain) NSMutableArray *keys;
-(void) resetSearch;
-(void) handleSearchForTerm:(NSString *)searchTerm;
@end
通知称姓名为动产。
下面一行将排除例外情况。
[array removeObjectsInArray:toRemove];
此处所用方法完全是:
-(void)handleSearchForTerm:(NSString *)searchTerm
{
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
for(NSString *key in self.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];
[toRemove release];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[sectionsToRemove release];
[table reloadData];
}
I am assigning array from the result of this [names valueForKey:key]; array is of type MutableArray What am I missing?
感谢!