iOS app crashing only when I capture image from camera not gallery, since last week

87 views Asked by At

Here are following are the code base in which crash happen. I tried to find the issue and try with the leak and instruments but still not able to fix it.

I had two options camera and gallery from the gallery I went to the shapeVC screen, and it working fine but when I clicked photo from the camera and went to shapeVC screen it crashed when scrolling and last printing indexpath --> Section: 7, Row: 0 and set camera and gallery permission.

Thread 1: EXC_BAD_ACCESS (code=2, address=0x16fa9fff0) line:- guard let cell = tableView.dequeueReusableCell(withIdentifier: "HomeAssetsTableCollectionCell", for: indexPath) as? HomeAssetsTableCollectionCell else { print("Failed to dequeue cell at IndexPath --> Section: \(indexPath.section), Row: \(indexPath.row)") return UITableViewCell() }


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if section == 0 {
        return 3
    } else {
        return 1
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if indexPath.section == 0  {
        let cell = tableView.dequeueReusableCell(withIdentifier: "HomeTableCollectionCell", for: indexPath) as! HomeTableCollectionCell
        cell.selectionStyle = .none
        cell.collectionView.backgroundColor = .clear//UIColor(named: "textFieldBackClr")
        if let layout = cell.collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
            layout.scrollDirection = .horizontal
        }
        cell.collectionView.accessibilityHint = "\(indexPath.row)"
        return cell
    } else {
        
        print("Indexpath --> Section: \(indexPath.section), Row: \(indexPath.row)")

        guard let cell = tableView.dequeueReusableCell(withIdentifier: "HomeAssetsTableCollectionCell", for: indexPath) as? HomeAssetsTableCollectionCell else {
            print("Failed to dequeue cell at IndexPath --> Section: \(indexPath.section), Row: \(indexPath.row)")
            return UITableViewCell()
        }
        cell.selectionStyle = .none
        if let layout = cell.collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
            layout.scrollDirection = .horizontal
        }
        
        cell.btnViewAll.tag = indexPath.section - 1
        cell.btnViewAll.addTarget(self, action: #selector(viewAllAction(sender:)), for: .touchUpInside)
        cell.collectionView.backgroundColor = .clear//UIColor(named: "textFieldBackClr")
        cell.lblTitleLeftConstraint.constant = isIpad ? 50 : 20
        cell.bgView.backgroundColor = .clear//UIColor(named: "textFieldBackClr")
        print(self.categoryVM.shapes[indexPath.section - 1])
        cell.collectionView.accessibilityHint = self.categoryVM.shapes[indexPath.section - 1].key
        cell.lblTitle.text = self.categoryVM.shapes[indexPath.section - 1].value
        cell.btnViewAll.isHidden = false
        cell.viewAllBtnHeight.constant = 29
        
        return cell
    }
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.section == 0{
        return isIpad ? 63 : 53
    } else {
        return self.shapesVM.numberOfImages(key: self.categoryVM.shapes[indexPath.section - 1].key) > 0 ? (isIpad ? 294 : 203) : 0
    }
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    guard (section == 0) else {
        return UIView(frame: .zero)
    }
    let headerView = Bundle.main.loadNibNamed("TitleHeader", owner: nil, options: nil)?.first as! TitleHeader
    headerView.titleLbl.text = "Popular Shapes"
    headerView.titleLbl.font = UIFont.abcWhyte(weight: .bold, size: isIpad ? 24 : 16)
    headerView.titleLblLetConstraint.constant = isIpad ? 50 : 20
    headerView.backgroundColor = .clear//UIColor(named: "textFieldBackClr")
    return headerView
}

func numberOfSections(in tableView: UITableView) -> Int 
{ return self.categoryVM.shapes.count + 1}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    guard (section == 0) else {
        return 0
    }
    return isIpad ? 107 : 60
}

func tableView(_ tableView: UITableView,willDisplay cell: UITableViewCell,forRowAt indexPath: IndexPath) {
    if let tableViewCell = cell as? HomeTableCollectionCell {
        print("HomeTableCollectionCell section --> \(indexPath.section)")
        tableViewCell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, forRow:indexPath.row,forSection: indexPath.section)
    } else  if let tableViewCell = cell as? HomeAssetsTableCollectionCell {
        print("HomeAssetsTableCollectionCell section --> \(indexPath.section)")
        let delay = self.shapesVM.numberOfImages(key: self.categoryVM.shapes[indexPath.section - 1].key) > 0 ? 0 : 0.5
        tableViewCell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, forRow: indexPath.row, forSection: indexPath.section, withDelay: delay)
    }
}

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if let tableViewCell = cell as? HomeTableCollectionCell {
        print("HomeTableCollectionCell section --> \(indexPath.section)")
        tableViewCell.collectionView.delegate = nil
        tableViewCell.collectionView.dataSource = nil
    } else  if let tableViewCell = cell as? HomeAssetsTableCollectionCell {
        print("HomeAssetsTableCollectionCell section --> \(indexPath.section)")
        tableViewCell.collectionView.delegate = nil
        tableViewCell.collectionView.dataSource = nil
    }
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if collectionView.tag == 0{
            return getRowForPopularKeys(collectionView: collectionView)
        }
        return shapesVM.numberOfImages(key: collectionView.accessibilityHint ?? "")
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if collectionView.tag == 0 {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomeTextCell", for: indexPath) as! HomeTextCell
            populateDataForPupularKey(collectionView: collectionView, cell: cell, indexPath: indexPath)
            return cell
        } else {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! ImageCell
            cell.cellImage.transform = .identity
            cell.viewMain.backgroundColor = UIColor(hexString: "121212")//UIColor(named: "textFieldBackClr")!
            let data = shapesVM.itemAtIndex(indexPath.row, key: collectionView.accessibilityHint ?? "")
            _APP_MANAGER.setImageUsingUrl(avtarImage: cell.cellImage, imageUrl: data.thumbnail_url)
            cell.proView.isHidden = !shapesVM.itemAtIndex(indexPath.row, key: collectionView.accessibilityHint ?? "").is_premium
            cell.viewMain.layer.borderColor = UIColor.clear.cgColor//UIColor(hexString: "5B5C61").cgColor
            cell.cellImage.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
            return cell
        }
    }

I hope some one look in to it and if any one face the same issue and help to give some hints or clue that would be so helpful.

Let me know if anyone need more details.

Thanks

0

There are 0 answers