Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Searchbar UITableView与数据库中的2个不同数据表_Objective C_Search - Fatal编程技术网

Objective c Searchbar UITableView与数据库中的2个不同数据表

Objective c Searchbar UITableView与数据库中的2个不同数据表,objective-c,search,Objective C,Search,现在我正在创建一个搜索栏。我正在使用JSON从数据库中检索数据。 目前我有这些 cell.textLabel.text = place.parkName; cell.detailTextLabel.text = place.parkDesc; 如何使cell.textlab.text继续使用其他数据数组中的数据 编辑:对不起,我的问题有点混乱,我的意思是,我目前有搜索栏工作,但它只搜索数据库中的一个表。我试图实现的是从数据库中的两个表中进行搜索 -(void)searchBar:(UI

现在我正在创建一个搜索栏。我正在使用JSON从数据库中检索数据。 目前我有这些

    cell.textLabel.text = place.parkName;
cell.detailTextLabel.text = place.parkDesc;
如何使cell.textlab.text继续使用其他数据数组中的数据

编辑:对不起,我的问题有点混乱,我的意思是,我目前有搜索栏工作,但它只搜索数据库中的一个表。我试图实现的是从数据库中的两个表中进行搜索

-(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;
}

我认为你的想法是错误的。与其先获取一个,然后获取另一个,为什么不同时获取两个并合并数组呢

因此,简而言之,只需将“placeArray”数组更改为两个数组合并后的“data”数组

如果两者之间的搜索不同,则为int i=0的循环创建一个;i<[placeArray count];i++然后是下一个循环i=[placeArray count];i<([placeArray count]+[shopArray count]-1);我++


如果你有任何问题,尽管问。我很高兴编辑这个

我想说的是,一旦我设置了cell.textlab.text=place.parkName,我如何为另一个数组设置它,例如shop.shopname请显示您的搜索代码!谢谢,我已经添加了搜索代码。进一步解释,我想让UITableView填充数据库中两个不同表(例如park表和shop表)的数据,是否可能?