ios - UITableViewCell 附件未随 searchResults 更新

标签 ios swift uitableview

我用这段代码在我的 tableView 上添加了一个复选标记附件:-

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){

    if (PFUser.currentUser()?.objectForKey("userType")) as? String != "Std"{

    let cell = tableView.cellForRowAtIndexPath(indexPath) as! UsersTableViewCell

    if (cell.accessoryType == UITableViewCellAccessoryType.Checkmark){

        cell.accessoryType = UITableViewCellAccessoryType.None;


        selectedTextLabels[indexPath] = nil


     }else{
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark;

        if (cell.accessoryType == UITableViewCellAccessoryType.Checkmark){

            if let Id = cell.channelIDLbl?.text {
                selectedTextLabels[indexPath] = Id

            }

         }
     }

   favoriteValues = Array(selectedTextLabels.values)

    print("\(favoriteValues)  outside")
}
}

它在第一次点击时工作正常我能够分配一个复选标记并再次点击同一个单元格根据需要删除该复选标记但问题是当我使用搜索功能时这个复选标记只是停留在它们的索引处(搜索结果是更新但不是附件)可能是因为这一行 selectedTextLabels[indexPath] 而发生的,因为我在选定的 indexPath 上添加附件而不是单元格内的值所以我如何添加这个附件在值上而不是 indexPath 或者还有其他方法吗?如果有人知道那么请指导我

附言- 如果我的问题的详细信息不够,请让我知道我会解决它,谢谢 :)

最佳答案

注意cell的复用,如果你上下滚动table view,cell可能会变如果你没有实现'prepare for reuse'方法,就不要检查单元格的数据。(在这种方法中,这是清理数据的最佳时机)

关于ios - UITableViewCell 附件未随 searchResults 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34561595/

相关文章:

ios - 将 UITableViewCell 的背景颜色设置为图案图像

ios - 从服务器获取数据后,直到单击屏幕后, TableView 才会显示数据

iphone - UITableView 中 Plist 中的数据排序不正确

swift - 从 UISearchBar 更改 UIBarButtonItem

objective-c - NSApplicationSupportDirectory无效的CFStringRef

ios - Action 完成时调用 func?

swift - 在哪里调用 becomeFirstResponder(),在 ViewDidAppear 或 ViewWillAppear?

ios - 自定义 UITableViewCell 中的按钮 Segue

ios - 回到导航 Controller

ios - 按钮可以包含 Apple Watch 应用程序中的组吗?