【发布时间】:2017-04-22 01:07:31
【问题描述】:
我知道这个问题正在打败一匹死马,但我已经搜索了所有以前的问题,但没有找到可以提供帮助的解决方案。我将 Firebase 用于我的后端和存储。当用户上传照片时,它会进入我的 Firebase 存储,并按照教程缓存照片以轻松处理数据。我访问缓存数据的方式是这样的:
let imageCache = NSCache<NSString, UIImage>()
extension UIImageView {
func loadImageUsingCachWithUrlString(urlString: String) {
self.image = nil
if let cachedImage = imageCache.object(forKey: urlString as NSString) as UIImage?{
self.image = cachedImage
return
}
let url = URL(string: urlString)
URLSession.shared.dataTask(with: url!, completionHandler: { (data,response,error) in
if error != nil{
print(error as Any)
return
}
DispatchQueue.main.async {
if let downloadedImage = UIImage(data: data!){
imageCache.setObject(downloadedImage, forKey: urlString as NSString)
self.image = downloadedImage
}
}
}).resume()
}
我通过函数“loadImageUsingCachWithUrlString”访问这个扩展
进入我的表格视图,我在每个单元格中加载用户姓名年龄生物等,我有 Firebase 持久性(以防有所不同),我将用户信息下载到单元格的方式是通过这个
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! UserCell
let cells = tableView.visibleCells
let user = users[indexPath.row]
let profileImageUrlThird = user.profileImageUrl
let tableViewHeight = tableView.bounds.size.height
cell.nameLabel.text = user.name
cell.bioLabel.text = user.aboutMe
cell.reviewRating.text = user.averageRating
cell.profileImageView.loadImageUsingCachWithUrlString(urlString: profileImageUrlThird!)
let tempNumber = user.profileView
let stringTemp = tempNumber?.stringValue
cell.profileViewCount.text = stringTemp
cell.imageView?.contentMode = .scaleAspectFill
cell.backgroundColor = UIColor.clear
cell.textLabel?.font = UIFont(name:"Avenir", size:22)
tableView.layer.borderWidth = 0;
tableView.layer.borderColor = UIColor.lightGray.cgColor
print(tableView.frame.height,tableView.frame.width)
//tableview height is 670 table view width is 414
print(cell.frame.width,cell.frame.height)
//cell width is 414 cell height is 330
for cell in cells {
cell.transform = CGAffineTransform(translationX: 0, y: tableViewHeight)
}
返回单元格 }
信息加载,一切都很好,但只要我拖动单元格就会消失。任何帮助将不胜感激,我已经坚持了将近一周
【问题讨论】:
标签: ios swift uitableview firebase tableviewcell