Iphone 表视图单元格图像在搜索后更改

Iphone 表视图单元格图像在搜索后更改,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我正在处理包含附件视图上的不同图像和每个单元格左侧的数据(文本)的表格视图单元格。最初,所有单元格都被其相关数据和图像占用。但是,当我在searchdisplaycontroller上搜索时,图像被分配为新数组。 例如:;我有表视图行,其中包含火车、公共汽车、飞机的图像和各自的文本。但当我搜索公共汽车时,文本显示良好,但imageview显示不相关的图像(比如火车图像)。 实现上述要求的逻辑是什么?我使用以下代码来配置单元 - (void)configureCell:(UITableViewCe

我正在处理包含附件视图上的不同图像和每个单元格左侧的数据(文本)的表格视图单元格。最初,所有单元格都被其相关数据和图像占用。但是,当我在searchdisplaycontroller上搜索时,图像被分配为新数组。 例如:;我有表视图行,其中包含火车、公共汽车、飞机的图像和各自的文本。但当我搜索公共汽车时,文本显示良好,但imageview显示不相关的图像(比如火车图像)。 实现上述要求的逻辑是什么?我使用以下代码来配置单元

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{
    btnImage = [[UIButton buttonWithType:UIButtonTypeCustom]retain];
    btnImage.frame = CGRectMake(688, 0, 80, 80);
    [btnImage setBackgroundImage:[arrImages objectAtIndex:indexPath.row] forState:UIControlStateNormal];
    [btnImage addTarget:nil action:@selector(DishImageClicked:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:btnImage];
    btnImage.tag = indexPath.row;
    NSLog(@"image clicked at index :%i",btnImage.tag);

}



// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *strCellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault 
                 reuseIdentifier:strCellIdentifier] autorelease];

        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    // assign text for the table view 
    if (tableView == self.searchDisplayController.searchResultsTableView)
    {

        cell.textLabel.text = [arrSearhResults objectAtIndex:indexPath.row];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:14];

        [self configureCell:cell atIndexPath:indexPath];

    }

    else      
    {
        // add image button 
        [self configureCell:cell atIndexPath:indexPath];
        cell.textLabel.text = [self.arrAllItems objectAtIndex:indexPath.row];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
             }
    return cell;
}

这是因为单元格是重复使用的,如果(tableView==self.searchDisplayController.searchResultsTableView)满足条件,则需要清除内容


如果您可以引用单元格内的imageview或按钮,只需清除图像。

我无法获取与其数据数组相关的搜索图像数组,因此我可以在显示搜索屏幕后显示它。我的问题不是重复使用单元格,我的问题是,在搜索正确的数据后,实际上获得了正确的图像。请发布configureCell方法,我认为问题在于该方法。