2017-11-22 8 views
0

enter image description hereObjective Cの - Googleの自動補完 - テーブルビュー - まず行目と2行は

をオーバーラップしている私は、私が探した場所のためのGoogleのオートコンプリートAPIを使用していますし、結果を表示するには、テーブルビューを使用しています客観C.に新しいです。

しかし、1行目と2行目がマージされています。あなたは何が問題になるのかお勧めしますか?

- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    if ((_gmsAutocompletePredictions.count || _searchBar.text.length) && section == 0) { 
     return "Search Result"; 
    } 
} 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return (_gmsAutocompletePredictions.count || _searchBar.text.length) ? 1 : 0; 
    } 

    - (NSInteger)tableView:(nonnull UITableView *)tableView  numberOfRowsInSection:(NSInteger)section { 
    if ((_gmsAutocompletePredictions.count || _searchBar.text.length) && section == 0) { 
     return _gmsAutocompletePredictions.count; 
    } 
    } 

    - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 
    // CPTLocationSearchCell User defined class which implements  UITableViewCell 
    CPTLocationSearchCell * cell = [tableView dequeueReusableCellWithIdentifier:CPTLocationSearchCellID forIndexPath:indexPath]; 
    cell.primaryLabel.attributedText = _gmsAutocompletePredictions[indexPath.row].attributedPrimaryText; 
    cell.secondaryLabel.attributedText = _gmsAutocompletePredictions[indexPath.row].attributedSecondaryText; 
    return cell; 

} 

// I think the problem with this function 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:  (NSIndexPath *)indexPath { 
    if (indexPath.section == 0 && indexPath.row == 0) { 
     NSLog(@"heightForRowAtIndexPath %lu %lu  ",indexPath.section,indexPath.row); 
     return 0.0; 
    } 
    return 60; 
    } 
+0

カスタムテーブルビューを使用していますか? –

+0

はいテーブルビューを使用して結果を表示しています。@ Rajesh。 –

+0

show cellforrow code –

答えて

0

最後に私は答えを見つけました。私はちょうど "heightForRowAtIndexPath"のifループをコメントし、今は動作しています。ありがとうRamesh

0

これを助けるかもしれない!

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    if (_gmsAutocompletePredictions.count>0) { 
     return _gmsAutocompletePredictions.count; 
    } 
    else 
    { 
     return 0; // or 1 pass when no record found 
    } 
    //return (_gmsAutocompletePredictions.count || _searchBar.text.length) ? 1 : 0; 
} 

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 

    if (_gmsAutocompletePredictions.count>0) { 
      // CPTLocationSearchCell User defined class which implements  UITableViewCell 
      CPTLocationSearchCell * cell = [tableView dequeueReusableCellWithIdentifier:CPTLocationSearchCellID forIndexPath:indexPath]; 
      cell.primaryLabel.attributedText = _gmsAutocompletePredictions[indexPath.row].attributedPrimaryText; 
      cell.secondaryLabel.attributedText = _gmsAutocompletePredictions[indexPath.row].attributedSecondaryText; 
      return cell; 
    } 
    else 
    { 
     CPTLocationSearchCell * cell = [tableView dequeueReusableCellWithIdentifier:CPTLocationSearchCellID forIndexPath:indexPath]; 
     return cell; 
    } 
} 
+0

あなたの助けをありがとう –

関連する問題