ios - 我如何使用 block 来更改 iOS 中的执行上下文?

标签 ios objective-c full-text-search objective-c-blocks

我使用搜索栏使用以下代码搜索文本,但在执行期间它卡在了我的 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
});

关于ios - 我如何使用 block 来更改 iOS 中的执行上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31078292/

相关文章:

ios - UITableView 分隔符插入引用在 Storyboard 中不起作用

mysqli_stmt::bind_param():变量数量与 mysql php 中准备好的语句中的参数数量不匹配

SQL:喜欢vs包含-不同的结果

java - 使用 lucene 的荧光笔和完整性的问题。

ios - 使用服务器证书签署 iPhone 配置文件

ios - 计算属性中的自调用

ios - 是否可以从 Apple Watch 应用程序中知道主机应用程序是否在前台?

ios - 如何: sort NSArray by date in descending order with nil date left on top of result set

iOS NSLayoutConstraint 使用 constraintWithItem 固定宽度

objective-c - 不兼容的 block 指针类型将 'void (^)(bool)' 发送到类型 'void(^)()' 的参数