コア データ/.sqlite をクエリするために検索機能をアプリに統合しましたが、問題なく動作します。しかし、問題があり、どのクラス構成を見ればよいかわかりません。誰かが私を光に向けてくれますか、ありがとう
基本的に私のモデルはこれです
TableView 1
製品カテゴリの表示
selectRow --> TableView2
TableView 2
選択したカテゴリの商品を表示
selectRow --> TableView3
UISearchBar をTableView 1に統合したので、ユーザーが必要な製品を検索したときに機能が必要で、テーブル ビューに製品の名前がすぐに表示されます。試してみたのですが、「検索した商品」を含む カテゴリーが表示されてしまいました。
では、これを正しく表示するにはどうすればよいでしょうか。また、構成のどのセクションを見ればよいのでしょうか?
UISearchDisplayController *searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[self performSelector:@selector(setSearchDisplayController:) withObject:searchDisplayController];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
[searchDisplayController setSearchResultsDelegate:self];
[searchDisplayController release];
[self.tableView setContentOffset:CGPointMake(0,self.searchDisplayController.searchBar.frame.size.height)];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
self.filteredListContent = [NSMutableArray arrayWithCapacity:[[[self fetchedResultsController] fetchedObjects] count]];
}
コードのこの部分ですか?
ありがとう
詳細情報を更新:
セルの構成
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *entity = nil;
if (self.searchIsActive){ // Configure the cell to show the searched item's name
entity = [[self filteredListContent] objectAtIndex:[indexPath row]];
cell.textLabel.textColor = [UIColor blackColor];
} else {// Configure the cell to show the category's name
cell.textLabel.textColor = [UIColor blackColor];
entity = [fetchedResultsController objectAtIndexPath:indexPath];
}
cell.textLabel.text = [entity valueForKey:@"nameEN"];
}
検索述語
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"ANY products.nameEN CONTAINS[cd] %@", searchText];
self.filteredListContent = [[[self fetchedResultsController] fetchedObjects] filteredArrayUsingPredicate:predicate];
}
コアデータ構造
Category{
nameEN
products <- one to many relation ->> Product.productcat
}
Product{
nameEN
spec
productcat <<-- many to one relation-> Category.products
}
ありがとうございました。