Ios 如何正确显示搜索结果?

Ios 如何正确显示搜索结果?,ios,swift,search,uisearchdisplaycontroller,Ios,Swift,Search,Uisearchdisplaycontroller,我有一个带有[化身图像-名称]的联系人列表表视图。我想在这些用户中搜索。为此,我创建了一个结构[User.swift]: struct User { let name : String let image: UIImage } 我通过以下途径进行搜索: func filterContentForSearchText(searchText: String, scope: String = "All") { self.filteredUsers = self.users.f

我有一个带有[化身图像-名称]的联系人列表表视图。我想在这些用户中搜索。为此,我创建了一个结构[User.swift]:

struct User {
    let name : String
    let image: UIImage
}
我通过以下途径进行搜索:

func filterContentForSearchText(searchText: String, scope: String = "All") {
    self.filteredUsers = self.users.filter({( user : User) -> Bool in
        let stringMatch = user.name.rangeOfString(searchText)
        return (stringMatch != nil)
    })
}
但它按预期只按字符串部分(在名称中)进行搜索。现在,我如何连接到它联系阿凡达图像

我将所有内容保存在一个数组中
var users=[User]()
为:

self.users.append(User(name: user.displayName, image: UIImage(data: photoData!)!))

那么,我如何才能将图像显示得离联系人姓名太近呢?

您应该能够获得您的用户

let userForRow:User = self.filteredUsers[indexPath.row]
然后访问图像

userForRow.image
可以使用标准单元格显示图像

cell.imageView.image = userForRow.image
在数据源的
cellforrowatinexpath

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let user = filteredUsers[indexPath.row]
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath indexPath)

    cell.textLabel.text = user.name
    cell.imageView.image = user.image

    return cell
}

如果我没弄错的话,您希望显示一个包含名称和图像的单元格的tableview。因此,只需在Interface Builder中使用标签和imageView创建此单元格(或根据需要编写代码),然后在返回表格的单元格时,只需将名称设置为标签的文本,将图像设置为imageView的图像

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

    var cell : UserContactCell?

    let userAtIndexPath = filteredUsers[indexPath.row]

    let name = userAtIndexPath.name
    let image = userAtIndexPath.image

    cell = tableView.dequeueReusableCellWithIdentifier("userContactCell") as? UserContactCell

    if(cell == nil)
    {
        tableView.registerNib(UINib(nibName: "UserContactCell", bundle: nil), forCellReuseIdentifier: "userContactCell")

        cell = tableView.dequeueReusableCellWithIdentifier("userContactCell") as? UserContactCell
    }
    }

    cell!.nameLabel.text = name
    cell!.imageView.image = image

    return cell!
}

对不起,我不明白你说的联系人头像是什么意思?要清楚,以身作则。你是说
用户的
结构中的
图像
?您可以直接从您的
filteredusters
array@katleta3000是的,没错!这是我的结构中的一个图像。你能帮我吗,我怎么用它?
user.image
?它将为您提供
UIImage
对象