首页 > 解决方案 > 线程 1:在 TableView Swift 上重新加载数据时,在 AppDelegate 上发出 SIGABRT 信号

问题描述

我正在使用自定义单元格填充 tableView。我从元组数组中获取单元格标签文本和 imageView 图像,(String:String)其中第一个值是商店名称,第二个值是存储在 firebase 存储中的图像的 Url。在我对 firebase 的查询结束时,我得到了availableShopsArray填充并重新加载 tableView 的数据。在cellForRowAt函数中,我将元组的两个参数分配给单元格标签和图像。但是在重新加载数据时,我在 AppDelegate 中遇到错误。

这是我声明函数的方式:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let cell = tableView.dequeueReusableCell(withIdentifier: "shopCell", for: indexPath as IndexPath) as! ShopTableViewCell
   cell.shopNameLabel.text = self.availableShopsArray[indexPath.row].0
   let url = URL(string: self.availableShopsArray[indexPath.row].1)
   let data = try? Data(contentsOf: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
   cell.imageView?.image = UIImage(data:data!)
   return cell         
}

这是我的单元格:

import UIKit

class ShopTableViewCell: UITableViewCell {

    @IBOutlet weak var makerImageView: UIImageView!
    @IBOutlet weak var shopImageView: UIImageView!
    @IBOutlet weak var shopNameLabel: UILabel!
    @IBOutlet weak var shopRatingLabel: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

任何想法

标签: iosswiftuitableview

解决方案


我要做的第一件事是创建一个异常来尝试查找错误的位置,这是一个关于如何做到这一点的有用教程:https ://mukeshthawani.com/debug-the-sigabrt-error-exception


推荐阅读