【问题标题】:Search Display Controller displaying incorrect image搜索显示控制器显示不正确的图像
【发布时间】:2015-07-30 13:25:05
【问题描述】:

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

应用加载时:

当我尝试搜索时:

如您所见,图像从头开始,并且图像视图没有为 iPhone 单元显示正确的图像。

提前感谢您的回答。

EDIT1: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

}

【问题讨论】:

  • 能否请您发布您的cellForRowAtindexPath: 方法?
  • pbush25,我提供了代码,谢谢您的快速响应

标签: ios swift uitableview xcode6 uisearchdisplaycontroller


【解决方案1】:

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

【讨论】:

  • 应该可以。另一种选择是在if...else 块内设置单元格属性。
猜你喜欢
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多