我已经查看了其他人发布的这类错误的帖子,但是UISearchBar没有,我没有可以将我的问题与以下内容联系起来:
简而言之,我正在玩searchBars并尝试构建基础知识.
我有2个阵列
@interface ViewController ()
{
NSMutableArray *dataList;
NSArray *searchResults;
}
Run Code Online (Sandbox Code Playgroud)
我使用以下内容填充了我的dataList数组:
dataList = [[NSMutableArray alloc] init];
[dataList addObject:@"This is row 1"];
[dataList addObject:@"That is row 2"];
....
[dataList addObject:@"More data in 20"];
Run Code Online (Sandbox Code Playgroud)
我设置了我的searchDisplayController:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString*) searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我有一个过滤功能:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
searchResults = [dataList filteredArrayUsingPredicate:resultPredicate];
}
Run Code Online (Sandbox Code Playgroud)
在最后一个过滤器函数中,我在最后一行开始时出现错误 searchResults =
2014-07-29 17:47:16.056 TestSearch[44628:60b] *** Terminating app …Run Code Online (Sandbox Code Playgroud) 我需要解析大量文本,并希望在此过程中向用户提供一些反馈。
环境是 Swift,虽然我确实在 Obj-C 中看到了一些代码 ([self performSelector:@selector(.....)),它没有多大意义。如果我知道如何将其嵌入到 Swift 方法中,我会这样做。
我可以用一个可重现的小案例来总结这个问题,它给出了相同的结果。即在循环中,增加一个值,显示进度并返回直到完成。显然,进度不会显示,因为 iOS 在刷新屏幕之前等待循环完成。
这是有道理的,所以我想在不同的时间间隔中断处理(即循环)并在继续处理之前刷新进度条。
我当前的代码如下所示:
@IBAction func goButton(sender: UIButton) {
currentCounter = 0
target = textTarget.text.toInt()!
step = textStep.text.toInt()!
updateProgressBar()
while currentCounter < target {
currentCounter += step
updateProgressBar()
}
}
func updateProgressBar() {
var percentage = Float(currentCounter) / Float(target) * 100
progressPercentage.text = "\(percentage) %"
println("progress = \(percentage)")
progressBar.setProgress(percentage, animated: false)
}
Run Code Online (Sandbox Code Playgroud)
我看到了以下内容:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
// do some task here...
}
dispatch_async(dispatch_get_main_queue()) {
// do another task here...
} …Run Code Online (Sandbox Code Playgroud)