この質問について無知で申し訳ありませんが、私はまだ基本を理解しようとしており、これについて数日間壁に頭をぶつけています。
私は基本的に、ユーザーが検索できるようにするためにNSArray
使用している を持っています。これは、ユーザーが入力するときに、検索条件に文字を含む結果をフィルタリングします。UITableView
接続するためのチュートリアルはかなりありますが、それらはすべて xib ファイルを使用してUITableViews
おり、プログラムですべてを追加しUISearchDisplayControllers
たいと考えています。
ユーザーがボタンをタップするUITableView
と、その内容が aに表示される があり、同じビューの上部にを追加したように見え、. しかし、3つすべてをうまくプレイすることはできないようです。UIView
UISearchBar
UISearchDisplayController
これが私がこれまでに持っているものです
- (IBAction)createSearchList:(id)sender {
//Make the list
AAPjsonParse * makeTheFullList = [[AAPjsonParse alloc] init];
fullListOfRecipesForTableView = [makeTheFullList generateFullListOfRecipes];
fullListForSearchResultsInTableView = fullListOfRecipesForTableView;
recipeListForTable = [fullListForSearchResultsInTableView allKeys];
recipeListForTable = [recipeListForTable sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
//Create the UITableView
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 300, 724) style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate = self;
//Add the TableView to the view
[self.searchView addSubview:tableView];
//Create a UISearchBar for the TableView
UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
//Set the searchBar as the delegate
searchBar.delegate = self;
//Add the searchBar to the UITableView
[self.searchView addSubview:searchBar];
//Create the searchViewController
UISearchDisplayController * searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
//Set the dataSource for the search as self
searchController.searchResultsDataSource = self;
//Set the results delegate as self – this is the view that's overlaid onto the full listing view (I think?)
searchController.delegate = self;
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [recipeListForTable count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * CellIdentifier = @"RecipeCell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString * cellTitle = [recipeListForTable objectAtIndex:indexPath.row];
cell.textLabel.text = cellTitle;
return cell;
}
また、さまざまなビットを格納するために、実装ファイルの上部にいくつかのものがあります
{
NSArray * recipeListForTable;
NSMutableArray * recipeListForSearch;
int selectedRecipeIndex;
NSDictionary * fullListOfRecipesForTableView;
NSMutableDictionary * fullListForSearchResultsInTableView;
UITableView * tableView;
}