gpt4 book ai didi

ios - didSelectRowAtIndexPath 对搜索结果不正确

转载 作者:可可西里 更新时间:2023-11-01 01:37:54 26 4
gpt4 key购买 nike

在搜索结果之前,我的 didSelectRowAtIndexPath 完美运行:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("fromContactsToChat", sender: OneRoster.userFromRosterAtIndexPath(indexPath: indexPath))
}

但是当我搜索某些内容并点击结果时,它会将我的联系人视为旧的 tableView 单元格索引路径。例如:

起初我的 tableView 看起来像:

Third User
First User
Second User

当我搜索First时,它会显示

First User

但是当我点击它时,它会将我的First User 视为旧表中的Third User,所以

OneRoster.userFromRosterAtIndexPath(indexPath: indexPath))

我获得了第三用户 凭证。我该如何更新和修复它?当我点击我的搜索显示中的单元格时,它会为这个搜索到的联系人打开。

有什么问题可以问我

更新

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> onlineUserCell {
let cell:onlineUserCell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! onlineUserCell
var us : User

if tableView == self.searchDisplayController!.searchResultsTableView {
us = filteredUsers[indexPath.row]
cell.username.text = us.name
cell.avatarImage.image = us.image

tableView.rowHeight = 60
cell.avatarImage.layer.cornerRadius = cell.avatarImage.frame.size.height / 2
cell.avatarImage.clipsToBounds = true
} else {
let user = OneRoster.userFromRosterAtIndexPath(indexPath: indexPath)
let photoData = OneChat.sharedInstance.xmppvCardAvatarModule?.photoDataForJID(user.jid)

cell.greenIndicator.alpha = 1
if user.isOnline() {
cell.greenIndicator.backgroundColor = UIColor.greenColor()
} else {
cell.greenIndicator.backgroundColor = UIColor.redColor()
// here here
}

cell.username.text = user.displayName
configurePhotoForCell(cell, user: user)

cell.avatarImage.layer.cornerRadius = cell.avatarImage.frame.size.height / 2
cell.avatarImage.clipsToBounds = true
}

return cell
}

更新 2

struct User {
let name : String
let image: UIImage
}

更新 3

public class func userFromRosterAtIndexPath(indexPath indexPath: NSIndexPath) -> XMPPUserCoreDataStorageObject {
return sharedInstance.fetchedResultsController()!.objectAtIndexPath(indexPath) as! XMPPUserCoreDataStorageObject
}

最佳答案

你的 didselectRowAtIndexPath 实现应该是这样的

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if tableView == self.searchDisplayController!.searchResultsTableView {
performSegueWithIdentifier("fromContactsToChat", sender: filteredUsers[indexPath.row])
}
else {
performSegueWithIdentifier("fromContactsToChat", sender: OneRoster.userFromRosterAtIndexPath(indexPath: indexPath))
}
}

即使在搜索结果中,您也在使用原始数据源,这就是问题所在

关于ios - didSelectRowAtIndexPath 对搜索结果不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33802367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com