当核心数据中找不到相关实体时,无法识别的选择器发送到实例

问题描述 投票:0回答:1

我有一个核心数据问题 - 我有两个实体,第二个是与第一个的一对多关系。当尝试使用第一个信息加载第一个详细视图控制器和第二个信息的UITableView时,我希望这个tableView代码允许我显示一个空白表,如果现在找到记录。相反,我发生了如上所述的崩溃。我试图将“事件”(相关的NSSet)覆盖到一个数组中,但我不确定如何调试此错误。感谢您的任何指示!

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "eventCell", for: indexPath)

     let eventsOnArray = selectedRecipient?.events.allObjects

    let event = eventsOnArray![indexPath.row] as! Event
    if selectedRecipient?.events.count != nil {
    cell.textLabel?.text = event.event

    }
    return cell
}

添加详细的堆栈跟踪 -

    2018-03-03 10:27:29.419115-0500 Card Tracker[5162:453078] -[Recipient events]: unrecognized selector sent to instance 0x60000009cbb0
2018-03-03 10:27:29.427781-0500 Card Tracker[5162:453078] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Recipient events]: unrecognized selector sent to instance 0x60000009cbb0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107fd212b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000103d79f41 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000108053024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x0000000107f54f78 ___forwarding___ + 1432
    4   CoreFoundation                      0x0000000107f54958 _CF_forwarding_prep_0 + 120
    5   Card Tracker                        0x0000000103434fca _T012Card_Tracker010ViewEventsC10ControllerC05tableC0SiSo07UITableC0C_Si21numberOfRowsInSectiontF + 410
    6   Card Tracker                        0x00000001034352e4 _T012Card_Tracker010ViewEventsC10ControllerC05tableC0SiSo07UITableC0C_Si21numberOfRowsInSectiontFTo + 68
    7   UIKit                               0x0000000104cd1b4c -[UITableView _numberOfRowsInSection:] + 62
    8   UIKit                               0x0000000104f840e1 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2389
    9   UIKit                               0x0000000104f8a5ab -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 487
    10  UIKit                               0x0000000104f8a711 -[UITableViewRowData heightForTable] + 61
    11  UIKit                               0x0000000104c7fa65 -[UITableView _updateContentSize] + 372
    12  UIKit                               0x0000000104cb067d -[UITableView _rebuildGeometry] + 66
    13  UIKit                               0x0000000104cae03c -[UITableView didMoveToWindow] + 145
    14  UIKit                               0x0000000104c2b147 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1748
    15  UIKit                               0x0000000104c44a81 -[UIScrollView _didMoveFromWindow:toWindow:] + 84
    16  UIKit                               0x0000000104c2ad84 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 785
    17  UIKit                               0x0000000104c1d1e1 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
    18  UIKit                               0x0000000104c1d0c8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 828
    19  UIKit                               0x0000000104c2dcbd -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1973
    20  UIKit                               0x0000000104b504e7 -[_UIParallaxDimmingView didMoveToWindow] + 179
    21  UIKit                               0x0000000104c2b147 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1748
    22  UIKit                               0x0000000104c2ad84 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 785
    23  UIKit                               0x0000000104c1d1e1 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
    24  UIKit                               0x0000000104c1d0c8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 828
    25  UIKit                               0x0000000104c2dcbd -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1973
    26  UIKit                               0x0000000104b4b259 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke_2 + 2305
    27  UIKit                               0x0000000104c25c60 +[UIView(Animation) performWithoutAnimation:] + 90
    28  UIKit                               0x0000000104b4a903 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 260
    29  UIKit                               0x0000000104c2c271 +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:] + 188
    30  UIKit                               0x0000000104b4a21b -[_UINavigationParallaxTransition animateTransition:] + 1270
    31  UIKit                               0x0000000104d3e3ee -[UINavigationController _startCustomTransition:] + 3678
    32  UIKit                               0x0000000104d543b4 -[UINavigationController _startDeferredTransitionIfNeeded:] + 686
    33  UIKit                               0x0000000104d556d3 -[UINavigationController __viewWillLayoutSubviews] + 150
    34  UIKit                               0x0000000104fb04e2 -[UILayoutContainerView layoutSubviews] + 231
    35  UIKit                               0x0000000121187008 -[UILayoutContainerViewAccessibility layoutSubviews] + 42
    36  UIKit                               0x0000000104c34a6d -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1439
    37  QuartzCore                          0x000000010b5d361c -[CALayer layoutSublayers] + 159
    38  QuartzCore                          0x000000010b5d77ad _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
    39  QuartzCore                          0x000000010b55e86c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 364
    40  QuartzCore                          0x000000010b58b946 _ZN2CA11Transaction6commitEv + 500
    41  UIKit                               0x0000000104b8d167 _afterCACommitHandler + 272
    42  CoreFoundation                      0x0000000107f74c07 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    43  CoreFoundation                      0x0000000107f74b5e __CFRunLoopDoObservers + 430
    44  CoreFoundation                      0x0000000107f59124 __CFRunLoopRun + 1572
    45  CoreFoundation                      0x0000000107f58889 CFRunLoopRunSpecific + 409
    46  GraphicsServices                    0x000000010a77b9c6 GSEventRunModal + 62
    47  UIKit                               0x0000000104b635d6 UIApplicationMain + 159
    48  Card Tracker                        0x0000000103417ea7 main + 55
    49  libdyld.dylib                       0x0000000109170d81 start + 1
    50  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

enter image description here

swift core-data ios11
1个回答
0
投票

发现了两个问题。在数据模型中,第二个实体称为卡而不是事件。正如@vadian上面指出的两个应该在viewDidLoad中执行加载。谢谢

© www.soinside.com 2019 - 2024. All rights reserved.