我有tableview
一个自定义单元格和一个搜索栏。我已经在单元格上标记了标签,因为我imageView
在那个单元格上也有一个标签。
该表显示良好的标签和图像,但在搜索中,方法 viewWithTag 似乎没有找到标记的标签。一旦我在搜索栏中输入一个字符,视图就会清除,就好像没有找到带有标签 100 的单元格一样。这是代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
iKl_Stretch *stretchpb = [self.filteredStretchList objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
nameLabel.text = stretchpb.name;
return cell;
} else {
iKl_Stretch *stretchpb = [self.categoryStretchList objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
nameLabel.text = stretchpb.name;
}
return cell;
}