0
我有一個應用程序,允許通過各種字段(名稱,城市,ID)搜索一個SQL數據庫我試圖實現搜索作爲隊列中的NSOperations。並且UI在第一次搜索之間更新,但由於某些原因,tableview在操作在後臺繼續時不會響應觸摸。不知道我已經錯過了,或者如果我需要一個定製的runloop的操作隊列如果是這樣希望得到一些幫助,由於我不是與這裏是我現有的代碼沒有得到控制回UI
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *searchText = searchBar.text;
[self.searchQueue cancelAllOperations]; //NSOperationQueue
[self.searchResults startSearching:searchText];
[self searchID:searchText];
NSInvocationOperation *operation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(searchName:) object:searchText];
[self.searchQueue addOperation:operation1];
[operation1 release];
//NSLog(@"Add city search");
NSInvocationOperation *operation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(searchCity:) object:searchText];
[self.searchQueue addOperation:operation2];
[operation2 release];
}
所以會發生什麼是再熟悉不過了用戶界面一直保留到第一次搜索結束(沒關係),並刷新表格視圖。由於每個操作在這段時間內完成它刷新的tableview,但是實現代碼如下將不會對觸摸做出反應......
本身看起來像這樣的任務..
-(void) searchCity:(NSString *)City{
searchObject *myCity = [[searchObject alloc] init];
self.searchResults.cityResults = [myCity searchCity:City]; //returns NSArray of items
if ([self.searchResults.cityResults count] == 0) {
[self.searchResults.cityResults addObject:[NSArray arrayWithObjects:@"Not Found.",@"",@"",@"",@"", nil]];
}
[self.searchResults refreshView];
//NSLog(@"Added from City Search\n%@",self.searchResults.cityResults);
}