草庐IT

ios - 线程 1 : EXC_BREAKPOINT CALayer removeAllAnimations message sent to deallocated

coder 2023-09-04 原文

有很多相同标题的问题,但不知何故,我觉得每个案例都不同,因为我的问题仍未解决,我不知道为什么,而且 Swift 的解决方案也不够。所以这是我的场景:

我用过 CarbonKit在单个 View Controller 中显示 4 个 View Controller 。 FourthViewController 使用 AlamoFire 发送一个 get 调用.它成功加载数据并重新加载 tableView。但是,当我拖动此 TableView 时,我的应用程序崩溃了,我得到了 EXC_BREAKPOINT,有时也得到了 EXC_BAD_ACCESS

这是我尝试过的:

  1. 经过搜索,我开始了解僵尸。所以我启用了它,当应用程序给我 EXC 时,我得到了这个:

-[CALayer removeAllAnimations]: message sent to deallocated instance

所以当我检查时,我可能在这个类中没有使用过动画。但考虑到它在 CarbonKit 内部,他们可能与它有关,但我无法弄清楚。

  1. 我从 xCode 运行 Product > Analyze,大​​部分蓝色图标都在 FBSDK 上,与此类无关,因此根本无法调试。

截图如下: 这是 Instruments 9.0 zombies 消息给我的:

我在 xCode 的控制台中得到这个: 如果您需要更多信息,我会更新我的问题。

更新
这是我使用 Alamofire 从网络获取数据时的代码。现在此调用成功运行,我可以向下滚动以查看表中加载的所有数据。但是,当我向上滚动时,它会因上述错误而崩溃。

let headers = [
            "security-token": "MY_SECURITY_CODE_HERE",
            "Content-Type": "application/x-www-form-urlencoded"
        ]

        let url = "URL_GOES_HERE"
        //print(url)
        Alamofire.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON { response in

            if let result = response.result.value as? [String: AnyObject] {

                switch response.result {
                case .success:
                    if result["status"] as! Int == 0
                    {
                        self.clearAllNotice()
                        let alert = UIAlertController(title: "Error",
                                                      message: "\(result["msg"] ?? "Our Server is not responding at the moment. Try again later!" as AnyObject)",
                            preferredStyle: UIAlertControllerStyle.alert)

                        let cancelAction = UIAlertAction(title: "OK",
                                                         style: .cancel, handler: nil)

                        alert.addAction(cancelAction)
                        self.present(alert, animated: true)
                    }
                    else
                    {
                        self.clearAllNotice()

                        for docReviewDict in (result["data"] as! [AnyObject]) {

                            let docReview = DoctorReview(dict: docReviewDict as! [String : AnyObject])
                            self.mainDoctorReviewsArray.append(docReview)
                        }

                        self.tableView.reloadData()
                    }
                case .failure(let error):
                    self.clearAllNotice()
                    let alert = UIAlertController(title: "Something is wrong",
                                                  message: error.localizedDescription,
                                                  preferredStyle: UIAlertControllerStyle.alert)

                    let cancelAction = UIAlertAction(title: "OK",
                                                     style: .cancel, handler: nil)

                    alert.addAction(cancelAction)
                    self.present(alert, animated: true)
                }
            } else {
              print("Somethins is wrong with the URL")
            }
        }

为了以防万一,这里是在表格 View 中加载的单元格。

最新:

根据我所做的评论:

DispatchQueue.main.async {
                        self.tableView.reloadData()
                        }

但我得到的结果还是一样

Thread 1: EXC_BAD_ACCESS (code=1, address=0xb4c4beb8)

let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewCell") 作为!当我在表格 View 上向下拖动时,ReviewsTableViewCell 行。

细胞的实现

类名是 ReviewsViewController,它有一个 @IBOutlet fileprivate var tableView: UITableView!

然后在 viewDidLoad() 中:

tableView.delegate = self
tableView.dataSource = self
tableView.tableFooterView = UIView()

然后我有 TableView 委托(delegate)和数据源:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mainDoctorReviewsArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewCell") as! ReviewsTableViewCell //WHEN THE APP IS CRASHED AS I DRAG THE TABLE VIEW IT CRASH ON THIS LINE. As this line is highlighted in red with message "Thread 1: EXC_BREAKPOINT (code=1, subcode=0x186ddd61c)"

        cell.userPhoto.layer.cornerRadius = cell.userPhoto.frame.width / 2;
        cell.userPhoto.layer.masksToBounds = true

        cell.userName.text = mainDoctorReviewsArray[indexPath.row].name

        cell.starRating.settings.fillMode = .precise

        if let rate = mainDoctorReviewsArray[indexPath.row].rating
        {
            cell.starRating.rating = Double(rate)!
        }
        else {
            cell.starRating.rating = 0
        }

        cell.desc.text = mainDoctorReviewsArray[indexPath.row].feedback
        cell.dateOfReview.text = mainDoctorReviewsArray[indexPath.row].dates
        cell.timeOfReview.text = mainDoctorReviewsArray[indexPath.row].times

        return cell
    }

在单元类中只有:

import UIKit
import Cosmos

class ReviewsTableViewCell: UITableViewCell {

    @IBOutlet var timeOfReview: UILabel!
    @IBOutlet var dateOfReview: UILabel!
    @IBOutlet var desc: UITextView!
    @IBOutlet var starRating: CosmosView!
    @IBOutlet var userName: UILabel!
    @IBOutlet var userPhoto: UIImageView!
    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
    }

}

tableView的截图在上面这个问题

这是加载 4 个 ViewController 的父类:dropbox.com/s/d5sh4ej1ssv6873/…这是具有 tableview 的类,在滚动时它使应用程序崩溃:dropbox.com/s/3kiju9hn3uewzar/ReviewsViewController.swift?dl‌​=0

最佳答案

正如上面提到的那样,它可能与使用不是来自主线程的 ui 对象有关。 如果您使用 xCode 9,您应该看到运行时警告。 (可以在EditScheme->Diagnostics->MainThreadChecker->pause on issues中设置checkmark)。

您还可以覆盖 ReviewsTableViewCell 的 dealloc 方法并添加一些日志\断言以检查它是否从主线程调用。

通常,如果您将 view\cell 传递给某个 block ,就会发生这种情况,并且在退出 block 时释放此对象时会发生崩溃。

关于ios - 线程 1 : EXC_BREAKPOINT CALayer removeAllAnimations message sent to deallocated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46683284/

有关ios - 线程 1 : EXC_BREAKPOINT CALayer removeAllAnimations message sent to deallocated的更多相关文章

随机推荐