0

現在、検索バーを作成しています。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;
}
4

1 に答える 1

0

あなたはこれを間違った方法で考えていると思います。一方を取得してから他方を取得する代わりに、両方を取得して配列をマージしてみませんか?

配列のマージ ドキュメント

つまり、「placeArray」配列を、2 つの配列が結合された「data」配列に変更するだけです。

2 つの検索が異なる場合は、for ループ for int i = 0; を 1 つ作成します。i < [placeArray カウント]; i++ そして次のループ i = [placeArray count]; i < ([placeArray カウント] + [shopArray カウント] - 1); i++

ご不明な点がございましたら、お気軽にお尋ねください。これを編集できてうれしいです。

于 2013-08-17T00:20:11.557 に答える