搜索显示控制器显示不正确的图像

Search Display Controller displaying incorrect image

我有以下问题。 我已经在用 swift 编写的 tableView 中设置了一个搜索栏。每个 tableView 单元格都有一个标签和一个图像。问题是,当我尝试搜索时,searchDisplayController 显示正确的标签但显示错误的图像(它显示数组中的第一张图像)。

应用加载时:

当我尝试搜索时:

如您所见,图像从头开始,图像视图未显示 iPhone 单元格的正确图像。

提前感谢您的回答。

编辑 1:cellForRowAtIndexPath 代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

    let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! CustomCell

    var friend : FriendItem

    if (tableView == self.searchDisplayController?.searchResultsTableView)
    {
        friend = self.filteredFriends[indexPath.row]

    }
    else
    {
        friend = self.friendsArray[indexPath.row]

    }



    cell.label1.text = friend.name

    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

    let item = friendsArray[indexPath.row]
    cell.setCell(item.name, image1: item.image)




    return cell

}

你正在从 friendsArray 中获取项目,但你应该在搜索时从 filteredFriends 数组中获取。尝试 cell.setCell(friend.name, image1: friend.image)