現在、検索バーを作成しています。JSON を使用してデータベースからデータを取得しています。現在、私はこれらを持っています
cell.textLabel.text = place.parkName;
cell.detailTextLabel.text = place.parkDesc;
cell.textlabel.text を他のデータ配列のデータと継続させるにはどうすればよいですか?
編集:申し訳ありませんが、私の質問は少し混乱していました。つまり、現在検索バーは機能していますが、データベース内の1つのテーブルからのみ検索するということです。私が達成しようとしているのは、データベース内の 2 つのテーブルから検索することです。
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
if(text.length == 0)
{
isFiltered = FALSE;
}
else
{
isFiltered = TRUE;
filteredTableData = [[NSMutableArray alloc] init];
for (Places* place in placeArray)
{
NSRange nameRange = [place.parkName rangeOfString:text options:NSCaseInsensitiveSearch];
NSRange descriptionRange = [place.parkDesc rangeOfString:text options:NSCaseInsensitiveSearch];
if(nameRange.location != NSNotFound || descriptionRange.location != NSNotFound)
{
[filteredTableData addObject:place];
}
}
}
[self.tableView reloadData];
}
#pragma mark - Table View Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return isFiltered ? searchedData.count : json.count;
//return json.count;
int rowCount;
if(self.isFiltered)
rowCount = filteredTableData.count;
else
rowCount = placeArray.count;
return rowCount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
//cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
//retrieve the current city object for use with this indexpath.row
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Places* place;
if(isFiltered)
place = [filteredTableData objectAtIndex:indexPath.row];
else
place = [placeArray objectAtIndex:indexPath.row];
cell.textLabel.text = place.parkName;
cell.detailTextLabel.text = place.parkDesc;
return cell;
}