我有一个数组,其中包含以下元素,在ViewDidLoad
方法中:
inputArray = [NSMutableArray arrayWithObjects:@"car", @"bus", @"helicopter", @"cruiz", @"bike", @"jeep", nil];
我有另一个UITextField
用于搜索元素。因此,一旦我在UITextField
中键入某些内容,我想检查该字符串是否存在于“inputArray”中。如果与inputArray中的元素不匹配,则从inputArray中删除相应的元素。
for (NSString* item in inputArray)
{
if ([item rangeOfString:s].location == NSNotFound)
{
[inputArray removeObjectIdenticalTo:item];//--> Shows Exception
NSLog(@"Contains :%@",containsAnother);
}
}
但是这段代码显示了异常,与“removeobject:”有关。
异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString rangeOfString:options:range:locale:]: nil argument'
*** First throw call stack:
`
s
)并查看哪一个是nil
。 - Rob