代码之家  ›  专栏  ›  技术社区  ›  Kamlesh Shingarakhiya

应用程序崩溃。正在尝试调试[UTableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:]

  •  0
  • Kamlesh Shingarakhiya  · 技术社区  · 4 年前

    我使用4个容器视图,每个容器视图有4个表视图。但奇怪的是,有些设备会崩溃,而不是所有设备都会崩溃。我遇到崩溃/登录Firebase Crashlytics。

    Crashed: com.apple.main-thread
    0  PuzzleStar                     0x1d5cf8 threeXtwoVC.tableView(_:cellForRowAt:) + 4309310712 (threeXtwoVC.swift:4309310712)
    1  PuzzleStar                     0x1d61bc @objc threeXtwoVC.tableView(_:cellForRowAt:) + 4309311932 (<compiler-generated>:4309311932)
    2  UIKitCore                      0xd42648 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 724
    3  UIKitCore                      0xd100c8 -[UITableView _updateVisibleCellsNow:] + 2524
    4  UIKitCore                      0xd232ec -[UITableView _visibleCellsUsingPresentationValues:] + 448
    5  PuzzleStar                     0x1d6458 threeXtwoVC.scrollViewDidScroll(_:) + 563 (threeXtwoVC.swift:563)
    6  PuzzleStar                     0x1d69e8 @objc threeXtwoVC.scrollViewDidScroll(_:) + 4309314024 (<compiler-generated>:4309314024)
    7  UIKitCore                      0xfc6a5c -[UIScrollView _notifyDidScroll] + 76
    8  UIKit                          0x6d968 -[UIScrollViewAccessibility _notifyDidScroll] + 44
    9  UIKitCore                      0xd10c68 -[UITableView _notifyDidScroll] + 60
    10 UIKitCore                      0xfaea88 -[UIScrollView setContentOffset:] + 1160
    11 UIKitCore                      0xd2fab8 -[UITableView setContentOffset:] + 284
    12 UIKitCore                      0xfbfc14 -[UIScrollView _smoothScrollWithUpdateTime:] + 2320
    13 UIKitCore                      0xfbfed4 -[UIScrollView _smoothScrollDisplayLink:] + 436
    14 QuartzCore                     0x13640 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 660
    15 IOKit                          0x7464 IODispatchCalloutFromCFMessage + 376
    16 CoreFoundation                 0x77b54 __CFMachPortPerform + 172
    17 CoreFoundation                 0x9b420 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
    18 CoreFoundation                 0x9a834 __CFRunLoopDoSource1 + 588
    19 CoreFoundation                 0x949f4 __CFRunLoopRun + 2332
    20 CoreFoundation                 0x93ba0 CFRunLoopRunSpecific + 572
    21 GraphicsServices               0x3598 GSEventRunModal + 160
    22 UIKitCore                      0xb2e2f4 -[UIApplication _run] + 1052
    23 UIKitCore                      0xb33874 UIApplicationMain + 164
    24 PuzzleStar                     0x53c8 main + 26 (HBText.swift:26)
    25 libdyld.dylib                  0x1568 start + 4 
    

    我将此代码用于表视图

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            
            if isShowAds && ((indexPath.row + 1) == arrCategories.count) && !(UserDefaults.standard.object(forKey: "isProUser") as? Bool ?? false) {
                
                guard let adsCell = tableView.dequeueReusableCell(withIdentifier: "BottomAds", for: indexPath) as? BottomAdsView else {
                    return UITableViewCell()
                }
                
                if !adsCell.adLoad {
                    DispatchQueue.main.async {
                        adsCell.setupAdsUI()
                    }
                }
                
                return adsCell
                
            }
            else if (!(UserDefaults.standard.object(forKey: "isProUser") as? Bool ?? false) && (indexPath.row > 4)) && arrCategories.count > 6 && (arrCategories[indexPath.row].id == arrCategories[5].id) {
               
               guard let adsCell = tableView.dequeueReusableCell(withIdentifier: "BottomAds", for: indexPath) as? BottomAdsView else {
                   return UITableViewCell()
               }
               
               if !adsCell.adLoad {
                   DispatchQueue.main.async {
                       adsCell.setupAdsUI()
                   }
               }
               
               return adsCell
           }
            else if (!(UserDefaults.standard.object(forKey: "isProUser") as? Bool ?? false) && (indexPath.row > 15)) && arrCategories.count > 16 && ( arrCategories[indexPath.row].id == arrCategories[16].id) {
                guard let adsCell = tableView.dequeueReusableCell(withIdentifier: "BottomAds", for: indexPath) as? BottomAdsView else {
                    return UITableViewCell()
                }
                
                if !adsCell.adLoad {
                    DispatchQueue.main.async {
                        adsCell.setupAdsUI()
                    }
                }
                
                return adsCell
            }
            
           else {
               
               guard let cell = tableView.dequeueReusableCell(withIdentifier: "threeXfour", for: indexPath) as? threeXfourCell else {
                   return UITableViewCell()
               }
               
               cell.cellTapped = {
                   if !self.isFromDB {
                       self.delegate?.threefourCellTapped(cardDataModel: self.arrCategories[indexPath.row], cellIndex: indexPath.row)
                   }
               }
               
               if arrCategories.count > 0 {
                   
                   cell.configthreefourCell = arrCategories[indexPath.row]
                   cell.imageLoaded = {
                       DispatchQueue.main.async {
                           if cell.imgBack != nil && cell.imgBack.image != nil {
                               let aspectRatio = cell.imgBack.image!.size.height/cell.imgBack.image!.size.width
                               let imageHeight = cell.vwBack.frame.width*aspectRatio
                               rowHeightsAspected[indexPath.row] = aspectRatio
                               //                        self.tblThreeFour.beginUpdates()
                               self.defaultHeight = imageHeight+17.0
                               self.rowHeights[indexPath.row] = imageHeight+17.0
                               //                        self.tblThreeFour.endUpdates()
                               //                        self.tblThreeFour.layoutIfNeeded()
                           }
                       }
                   }
                   
                   //Adding tag and handle click event for Preview & Favourite
                   cell.btnPreview.tag = indexPath.row
                   cell.btnPreview.addTarget(self, action: #selector(onClickPreview), for: .touchUpInside)
                   
                   cell.btnFav.tag = indexPath.row
                   cell.btnFav.addTarget(self, action: #selector(onClickFav), for: .touchUpInside)
                   
                   if !cardFavExists(fileName: arrCategories[indexPath.row].zipFile.name, entitiName: puzzlestartDB.entitynameFavourite) {
                       cell.btnFav.setImage(UIImage.init(named: "ic_fav"), for: .normal)
                   }
                   else {
                       cell.btnFav.setImage(UIImage.init(named: "ic_fav_fill"), for: .normal)
                   }
               }
               tblThreeFour.clipsToBounds = false
               return cell
           }
        }
    
    0 回复  |  直到 4 年前
    推荐文章