【发布时间】:2015-04-16 08:39:54
【问题描述】:
我想在一个视图控制器中有 2 个表,并且只在其中一个中进行搜索。我能怎么做 ?
我知道如何实现搜索栏,但我不知道如何在表格之间进行区分。我试图用标签来做这件事,但没有用。
任何建议都会有所帮助。
UITableViewCell *cell ;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
if (tableView.tag==1) {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.textLabel.text = [self.searchResult objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text = self.tableData[indexPath.row];
}}
else if (tableView.tag==0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [historique objectAtIndex:indexPath.row];
}
return cell;
}
我也在尝试这个:
即使我这样说
self.tableSource= self.searchDisplayController.searchResultsTableView; the result is the same
【问题讨论】:
标签: ios objective-c uitableview uisearchbar