arrays - 将新元素附加到数组导致应用程序崩溃的异常错误

标签 arrays swift

我正在从 API 获取项目列表。这很好用。我的 View Controller 中有一个局部变量,因此在成功从 API 获取项目后,我将重新加载我的 TableView 。

最近,在我将数组内容从 API 附加到我的本地数组变量的行中,我现在遇到了崩溃。我对 SO 进行了多次研究,但没有成功。我不断收到同样的错误

这是导致崩溃的代码


不相关的 API 获取代码


     if refresh {
                    self?.items = ticketItems
                }
                else {
                    self?.ticketItems.append(contentsOf: 
                    ticketItems)
                }

通常,在追加数组内容时我不应该崩溃。这对我来说很奇怪。请查找错误信息:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: !CGSizeEqualToSize(size, CGSizeZero)'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000116bb86fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x00000001157adac5 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000116bb8482 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000010fe51927 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
    4   UIKitCore                           0x000000011e0f0399 -[_UIUpdateVisibleCellsContext addSize:forIndexPath:] + 385
    5   UIKitCore                           0x000000011e0e8643 -[UICollectionViewFlowLayout shouldInvalidateLayoutForPreferredLayoutAttributes:withOriginalAttributes:] + 409
    6   UIKitCore                           0x000000011e0a2f08 -[UICollectionView _checkForPreferredAttributesInView:originalAttributes:] + 559
    7   UIKitCore                           0x000000011e0a3c24 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 1596
    8   UIKitCore                           0x000000011e0a35e2 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31
    9   UIKitCore                           0x000000011e0a8a8c -[UICollectionView _updateVisibleCellsNow:] + 6120
    10  UIKitCore                           0x000000011e0adbb6 -[UICollectionView layoutSubviews] + 365
    11  UIKitCore                           0x000000011ecf99c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
    12  QuartzCore                          0x0000000111cf7eae -[CALayer layoutSublayers] + 173
    13  QuartzCore                          0x0000000111cfcb88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
    14  QuartzCore                          0x0000000111d08ee4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72
    15  QuartzCore                          0x0000000111c783aa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328
    16  QuartzCore                          0x0000000111caf584 _ZN2CA11Transaction6commitEv + 608
    17  QuartzCore                          0x0000000111cafede _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
    18  CoreFoundation                      0x0000000116b1f0f7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    19  CoreFoundation                      0x0000000116b195be __CFRunLoopDoObservers + 430
    20  CoreFoundation                      0x0000000116b19c31 __CFRunLoopRun + 1505
    21  CoreFoundation                      0x0000000116b19302 CFRunLoopRunSpecific + 626
    22  GraphicsServices                    0x000000011be162fe GSEventRunModal + 65
    23  UIKitCore                           0x000000011e82bba2 UIApplicationMain + 140
    24  Sterling Bank App                   0x000000010c1be211 main + 225
    25  libdyld.dylib                       0x0000000118307541 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

我得到了确切的错误:

'Invalid parameter not satisfying: !CGSizeEqualToSize(size, CGSizeZero)'

这只是因为我忘记将 translatesAutoresizingMaskIntoConstraints 设置为 false 我要添加到单元格的 contentView 的 subview ...

关于arrays - 将新元素附加到数组导致应用程序崩溃的异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57071829/

相关文章:

java - 使用 for-each 循环或使用迭代器迭代 JSON 数组 (Android Studio)

arrays - 如何使用powershell将字符串变量拆分为两个数组对象变量?

ios - 在 SwiftUI 中根据明暗模式更改 buttonStyle 修饰符

c++ - 为什么 gcc 允许使用大于数组的字符串文字初始化 char 数组?

c# - 位置0处无行错误处理

php - 查找一个mysql数据库行到一个字符串数组php

ios - Swift:获取线程 1:发出 SIGABRT 信号,但我的所有 socket 均已连接

swift - 在单元测试中等待 Alamofire

ios - Swift:如何在没有 topBorder 的情况下向 UITabBarController 添加阴影

ios - Swift iOS - 如何将 UIPopoverBackgroundView 类中的方法连接到不同类中的 PopoverController?