NSMutableArray 搜索
我有一个 UISearchBar,正在对数组执行搜索并显示结果。搜索对于第一个字母非常有效,但是当我在搜索中添加字母甚至按退格键时,应用程序就会崩溃。这是我正在使用的代码:
for (NSString *sTemp in arrCatSearch)
{
NSRange titleResultsRange = [sTemp rangeOfString:strSearch options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[searchArray addObject:[catalog.catalogItems objectAtIndex:i]];
i++;
}
应用程序在 NSRange 行中崩溃。
I have a UISearchBar and I am performing a search on an array and displaying result. The search works perfect for the first letter but the application crashes when I add a letter in search or even when I press backspace. Here is the code I am using:
for (NSString *sTemp in arrCatSearch)
{
NSRange titleResultsRange = [sTemp rangeOfString:strSearch options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[searchArray addObject:[catalog.catalogItems objectAtIndex:i]];
i++;
}
The application crashes in the NSRange line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用
NSRange
,例如:在搜索栏的委托方法中
I am using
NSRange
like :in search bar's delegate methods
在数组中搜索结果应该使用 NSPredicate 类来完成:
Searching an array for results should be done with the NSPredicate class:
我认为这应该会给你一个更好的结果。
I think this should give you a better result.