我正在使用搜索栏使用以下代码搜索文本,但是在执行过程中它卡住了我的UI,因此如何使用任何建议来执行该代码?
我的代码:
for(NSMutableDictionary *dicSearch in arrSearchResult)
{
NSString *strParagraph = [self stringByStrippingHTML:[dicSearch objectForKey:@"Topic_content"]];
NSString *strChapter = [dicSearch objectForKey:@"Chapter_name"];
NSString *strChapterId = [dicSearch objectForKey:@"Chapter_id"];
NSString *strTopicId = [dicSearch objectForKey:@"Topic_Id"];
NSArray *arr = [strParagraph componentsSeparatedByString:@"\n"];
for(NSString *strContent in arr)
{
if ([[strContent uppercaseString] rangeOfString:[objSearchBar.text uppercaseString]].location != NSNotFound)
{
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:strContent forKey:@"Content"];
[dic setObject:strChapter forKey:@"Chapter_name"];
[dic setObject:strChapterId forKey:@"Chapter_id"];
[dic setObject:strTopicId forKey:@"Topic_Id"];
[arrSearchedChapter addObject:dic];
}
}
}
最佳答案
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//put your code in here
});