unrecognized selector sent to instance when no related entities found in Core Data

淺唱寂寞╮ 提交于 2019-12-02 17:23:26

问题


I have a Core Data problem - I have two entity's with the second being a one to many relation ship to the first. When trying to load a detailed view controller on the first with the first one's information and a UITableView fo the details of the 2nd, I am hoping this tableView code would allow me to show a blank table if now records are found. Instead I get a crash as indicated above. I have tried to cover the "Event" (the related NSSet) into an array, but I am not sure how to debug this error. Thanks for any pointers!

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
}

Adding detailed Stack Trace -

    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


回答1:


Two problems uncovered. one in the data model the secondary entity is called card not events. And two as pointed out by @vadian above should do the load in the viewDidLoad. Thanks



来源:https://stackoverflow.com/questions/49061018/unrecognized-selector-sent-to-instance-when-no-related-entities-found-in-core-da

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!