搜索栏控制器 - 搜索结果时崩溃
我正在实现一个搜索栏控制器来搜索表视图。下面执行搜索的方法代码崩溃,并出现错误“-[__NSArrayM rangeOfString:options:]: 无法识别的选择器发送到实例 0x65558e0'
locationInfo 数组是一个包含 26 个数组的数组,每个数组都包含由多个对象组成的数组 吗
任何人都可以建议为什么代码崩溃
?
- (void)handleSearchForTerm:(NSString *)searchTerm
{
[self setSavedSearchTerm:searchTerm];
if ([self searchResults] == nil)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults:array];
[array release], array = nil;
}
[[self searchResults] removeAllObjects];
if ([[self savedSearchTerm] length] != 0)
{
for (NSString *currentString in [self locationInfo])
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self searchResults] addObject:currentString];
}
}
}
}
I am implementing a search bar controller to search a table view. The below method code which performs the search is crashing with the error "-[__NSArrayM rangeOfString:options:]: unrecognized selector sent to instance 0x65558e0'
The locationInfo array is an array containing 26 arrays, each of which contains a number of objects made up of strings.
Can anyone suggest why the code is crashing ?
Thank you.
- (void)handleSearchForTerm:(NSString *)searchTerm
{
[self setSavedSearchTerm:searchTerm];
if ([self searchResults] == nil)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults:array];
[array release], array = nil;
}
[[self searchResults] removeAllObjects];
if ([[self savedSearchTerm] length] != 0)
{
for (NSString *currentString in [self locationInfo])
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self searchResults] addObject:currentString];
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您在问题中所说,“locationInfo”是包含 26 个数组的数组,
所以,
[self locationInfo] 中的 currentString 将仅返回一个数组,因此尝试编写如下所示的内容:
for (NSArray *currentArray in [self locationInfo])
}
或类似的内容
As you stated in question that "locationInfo" is array containing 26 arrays,
so,
currentString in [self locationInfo] will return an array only so try to write something like below :
for (NSArray *currentArray in [self locationInfo])
}
or something like this
根据您收到的错误,似乎
[self locationInfo]
返回一个数组 (NSArray
) 而不是字符串 (NSString
)你在期待。Based on the error you're getting, it seems
[self locationInfo]
returns an array (NSArray
) and not a string (NSString
) as you're expecting.