我有一个tableview
与自定义单元格和搜索栏。我在单元上标记了标签,因为我在该单元上也有一个imageView
。viewWith标签不返回搜索对象
该表格显示的标签和图像很好,但在搜索中,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;
}
为什么你搜索与标签100子视图?你使用标准类UITableViewCell创建单元格,为什么你认为在标准单元格内有一个标签为100的子视图? – viggio24
因为我为默认存在的那个标签分配了一个值。这是不正确的? –
你在哪里设置每个单元的标签标签? –