当在Core Data中找不到相关实体时,无法识别的选择器发送到实例 [英] unrecognized selector sent to instance when no related entities found in Core Data

查看:47
本文介绍了当在Core Data中找不到相关实体时,无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
}

添加详细的堆栈跟踪-

    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

推荐答案

发现了两个问题。在数据模型中,第二个实体称为卡非事件。上面@vadian指出的两个应该在viewDidLoad中完成加载。谢谢

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

这篇关于当在Core Data中找不到相关实体时,无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆