现在我正在创建一个搜索栏。我正在使用 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;
}