There are a lot of question with the same title but somehow I felt that every case is different as my problem is still not resolved and I've no clue why and also there are not enough solutions for Swift. So here is my scenerio:
I've used CarbonKit to show 4 view controllers in a single view controller. The FourthViewController
sends a get call using AlamoFire. It successfully loads the data and reload tableView
. However when I drag this table view my app crashes and I get EXC_BREAKPOINT
and sometimes EXC_BAD_ACCESS
for the same thing.
Here is what I've tried:
- Upon searching I came to know about zombies. So I enabled it and when the app gives me EXC I get this:
-[CALayer removeAllAnimations]: message sent to deallocated instance
So as I checked there was no animation I might have been using in this class. But considering it's inside CarbonKit they might have something to do with it but I'm unable to figure it out.
- I run Product > Analyze from xCode and the most of the blue icons are on FBSDK which have nothing to do with this class so it was not useful to debug at all.
Here are the screenshots:
and
and here is what Instruments 9.0 zombies message gave me:
and
I get this in console of xCode:
If you need more information I'll update my questions.
UPDATE
Here is my code when I'm getting the data from web using Alamofire. Now this call runs successfully and I can scroll down to view all the data that is loaded in the table. But when i scroll up then it crashes with the above errors.
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")
}
}
Just in case here is the cell which is loaded in the tableview.
Latest:
Based on the comment I've done this:
DispatchQueue.main.async {
self.tableView.reloadData()
}
but still the same result I'am getting
Thread 1: EXC_BAD_ACCESS (code=1, address=0xb4c4beb8)
on let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewCell") as! ReviewsTableViewCell
line when I drag down on table view.
IMPLEMENTATION OF CELL
The class name is ReviewsViewController
which has a @IBOutlet fileprivate var tableView: UITableView!
.
Then in viewDidLoad()
:
tableView.delegate = self
tableView.dataSource = self
tableView.tableFooterView = UIView()
Then I've table view delegate and datasource:
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
}
and in the cell class there is just:
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
}
}
The screenshot of tableView
is above in this question.
This is the parent class under which 4 ViewControllers loads: dropbox.com/s/d5sh4ej1ssv6873/… And this is the class which has the tableview is and on scroll it crashed the app: dropbox.com/s/3kiju9hn3uewzar/ReviewsViewController.swift?dl=0