当我在搜索字段中输入两个以上的字符时,将引发异常。我使用NSComparisonResult在UITableView上显示结果:
- (void)filterContentForSearchText:(NSString*)searchText
{
for (mystring in self.array)
{
NSComparisonResult result = [mystring compare:searchText options:(NSCaseInsensitiveSearch)
range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
NSUInteger index=[self.array indexOfObjectIdenticalTo:mystring];
NSUInteger maxindex = index + 50;
for (index ; (index < [self.array count] && index <= maxindex && index!= NSNotFound); index ++)
{
[self.filteredListContent addObject:[NSDictionary dictionaryWithObjectsAndKeys:[self.array objectAtIndex:index],@"english",[self.secondarray objectAtIndex:index],@"translated",nil]];
}
break;
}
}
输出显示:
-[UIDeviceWhiteColor compare:options:range:]: unrecognized selector sent to instance 0x5e4a5d0
2011-11-06 12:10:51.932 XXX[2583:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceWhiteColor compare:options:range:]: unrecognized selector sent to instance 0x5e4a5d0'
在这种情况下,UIDeviceWhiteColor是什么意思?
self.array = [[NSArray alloc] initWithArray:
[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"first" ofType:@"txt"]
encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"]];
self.secondarray = [[NSArray alloc] initWithArray:
[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"second" ofType:@"txt"]
encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"]];
最佳答案
这是因为您的UIDeviceWhiteColor
中某处有一个self.array
,应该仅由NSString
组成。您如何填充此数组?