【问题标题】:Crashlytics strange crash report - com.apple.main-thread. EXC_BREAKPOINTCrashlytics 奇怪的崩溃报告 - com.apple.main-thread。 EXC_BREAKPOINT
【发布时间】:2020-03-22 15:53:50
【问题描述】:

我收到了一个奇怪的 Firebase Crashlytics 报告,我们无法重现或跟踪该问题,只有 1.5% 的用户遇到此崩溃,但我们需要修复它。

Crashed: com.apple.main-thread.   EXC_BREAKPOINT 0x0000000100b057a4    
SearchViewController.tableView(_:cellForRowAt:)
0  AppName                        0x100b057a4 SearchViewController.tableView(_:cellForRowAt:) + 4309342116 (<compiler-generated>:4309342116)
1  AppName                        0x100b05834 @objc SearchViewController.tableView(_:cellForRowAt:) + 4309342260 (<compiler-generated>:4309342260)
2  UIKitCore                      0x211f3b618 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 680
3  UIKitCore                      0x211f3bb18 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
4  UIKitCore                      0x211f08320 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2260
5  UIKitCore                      0x211f25640 -[UITableView layoutSubviews] + 140
6  UIKitCore                      0x2121b4170 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1292
7  QuartzCore                     0x1e9a6cc60 -[CALayer layoutSublayers] + 184
8  QuartzCore                     0x1e9a71c08 CA::Layer::layout_if_needed(CA::Transaction*) + 332
9  QuartzCore                     0x1e99d43e4 CA::Context::commit_transaction(CA::Transaction*) + 348
10 QuartzCore                     0x1e9a02620 CA::Transaction::commit() + 640
11 QuartzCore                     0x1e9a0315c CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
12 CoreFoundation                 0x1e54c04fc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
13 CoreFoundation                 0x1e54bb224 __CFRunLoopDoObservers + 412
14 CoreFoundation                 0x1e54bb7a0 __CFRunLoopRun + 1228
15 CoreFoundation                 0x1e54bafb4 CFRunLoopRunSpecific + 436
16 GraphicsServices               0x1e76bc79c GSEventRunModal + 104
17 UIKitCore                      0x211d1cc38 UIApplicationMain + 212
18 AppName                        0x100a19654 main + 18 (RatingDetailsTableViewCell.swift:18)
19 libdyld.dylib                  0x1e4f7e8e0 start + 4
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let item = list[indexPath.row]
        switch selectedType {
        case .book, .bundle, .gadget, .author:
            let cell = tableView.dequeue(cellForItemAt: indexPath) as ItemTableViewCell
            cell.configure(item)
            return cell

        case .none:
            return UITableViewCell()
        }
    }
    public func configure(_ item: Itemizable) {
        self.item = item
        // Adjest imageview shape depending on item
        let isAuthor = ItemType.author == item.type
        twoThirdRatioConstraint.isActive = !isAuthor
        oneRatioConstraint.isActive = isAuthor
        imgView.layer.cornerRadius = isAuthor ? imgView.bounds.width / 2 : 10
    }

提前谢谢..

更新 1

添加数组列表和numberOfRowsInSection

    fileprivate var list = [Itemizable]() {
        didSet {
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return list.count
    }

【问题讨论】:

  • 您好,能否在您的问题中添加 numberOfRowsInSection 方法?
  • 嘿,你解决了这个问题吗?
  • 任何人都可以帮助解决这个长期以来没有找到解决方案的问题吗?
  • 我会推荐这个答案 stackoverflow.com/a/30593673/10798716 从列表中获取项目并在尝试返回单元格之前检查是否不为零。由于互联网连接速度慢和结果多变,这可能会发生。跨度>

标签: ios swift uitableview crashlytics


【解决方案1】:

我建议你添加一个基本的保护。

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

        // A good practice to prevent crashes is to always compare 
        // the number of objects and the indexPath.row

        guard list.count > indexPath.row else { 
            // You could add a log here to know if that's your problem
            return UITableViewCell() 
        }

        let item = list[indexPath.row]
        switch selectedType {
        case .book, .bundle, .gadget, .author:
            let cell = tableView.dequeue(cellForItemAt: indexPath) as ItemTableViewCell
            cell.configure(item)
            return cell

        case .none:
            return UITableViewCell()
        }
    }

【讨论】:

    【解决方案2】:

    有一个小窗口,您有一个用于numberOfRowsInSection 的新列表,但reloadData() 未被调用,因为它是异步执行的。您应该做的是强制在主线程上执行分配列表的新值,然后立即调用 reloadData() 而不调度它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多