私はtableview
にカスタムセルと検索バーがあります。私はそのセルにimageView
も持っているので、私はセルのラベルにタグを付けました。viewWithTagは検索でオブジェクトを返しません
テーブルはラベルと画像でうまく表示されますが、検索では、メソッドviewWithTagではタグ付きラベルが見つからないようです。検索バーに文字を入力すると、タグが100のセルが見つからなかったかのようにビューが消去されます。たぶんラベルは、セルのcontentView
のサブビューです
- (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;
}
:で
を?標準クラスのUITableViewCellを使用してセルを作成していますが、なぜその標準セルの内部にタグ100のサブビューがあると思いますか? – viggio24
私はそのタグにデフォルトで存在する値を割り当てたので。これは間違っていますか? –
各セルのラベルタグを設定する場所はどこですか? –