0

我正在获取 JSONArray 数据并在表中显示电话号码
我在 UITableView 中使用 UISearchBar。

当我在搜索栏中输入时,它会重新加载数据并在第一个单元格中显示类型值。

但我单击第一个单元格意味着它显示旧数组值。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
   if (isSearching) 
   {
        cell.textLabel.text = [searchResultArray objectAtIndex:indexPath.row];  
   }
   else 
   {
        cell.textLabel.text = [phoneNoArray objectAtIndex:indexPath.row];
   }
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{
   [searchResultArray removeAllObjects];
   if([searchText length] != 0)
   {
        isSearching = YES;
        [self searchTableList];
   }
   else 
   {
        isSearching = NO;
   }
   [self.tableView reloadData];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    tempString = [jsonArray objectAtIndex:indexPath.row];

}
4

1 回答 1

0

当您将 isSearching 设置为 yes 时。现在表的数据源已经改变。并且您已重新加载数据。

你也应该更新你的数据源方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (isSearching) {
    return [searchResultArray count];
}
else
{
  return [phoneNoArray count];
 }
}

高温高压

于 2015-08-17T11:30:10.453 回答