我有一個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
因爲我爲默認存在的那個標籤分配了一個值。這是不正確的? –
你在哪裏設置每個單元的標籤標籤? –