THREAD 1:EXC_BREAKPOINT CALayer removeAllAnimations消息发送到deallocated

Cha*_*lha 7 nszombie ios swift swift4

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

我使用CarbonKit在一个视图控制器中显示4个视图控制器.在FourthViewController发送使用get调用AlamoFire.它成功加载数据并重新加载tableView.然而,当我拖动这个表视图时,我的应用程序崩溃了,我得到了EXC_BREAKPOINT有时EXC_BAD_ACCESS同样的事情.

这是我尝试过的:

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

- [CALayer removeAllAnimations]:发送到解除分配实例的消息

所以当我检查时,我可能没有在这个课程中使用过的动画.但考虑到它在CarbonKit中,它们可能与它有关,但我无法弄明白.

  1. 我从xCode 运行Product> Analyze,大部分蓝色图标都在FBSDK上,这与这个类无关,所以它根本没有用.

以下是截图: EXC_BREAKPOINTEXC_BAD_ACCESS 以下是Instruments 9.0僵尸消息给我的信息: 僵尸消息更详细的僵尸

我在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")
            }
        }
Run Code Online (Sandbox Code Playgroud)

以防这里是在tableview中加载的单元格. 在此输入图像描述

最新:

根据评论我做了这个:

DispatchQueue.main.async {
                        self.tableView.reloadData()
                        }
Run Code Online (Sandbox Code Playgroud)

我得到的结果仍然相同

线程1:EXC_BAD_ACCESS(代码= 1,地址= 0xb4c4beb8)

let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewCell") as! ReviewsTableViewCell线的时候我拖累上表视图.

细胞的实施

班级名称ReviewsViewController有一个@IBOutlet fileprivate var tableView: UITableView!.

然后在viewDidLoad():

tableView.delegate = self
tableView.dataSource = self
tableView.tableFooterView = UIView()
Run Code Online (Sandbox Code Playgroud)

然后我有表视图委托和数据源:

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
    }
Run Code Online (Sandbox Code Playgroud)

在细胞类中只有:

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
    }

}
Run Code Online (Sandbox Code Playgroud)

截图tableView是在这个问题的上面.

这是4个ViewControllers加载的父类:dropbox.com/s/d5sh4ej1ssv6873/...这是具有tableview的类,在滚动时它崩溃了app:dropbox.com/s/3kiju9hn3uewzar/ReviewsViewController.swift? DL = 0

小智 0

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

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

通常,如果您将视图\单元格传递到某个块,并且在退出块时释放该对象时会发生崩溃,则会发生这种情况。