prepareForSegue在分配NSManagedObject时崩溃,但为什么?

时间:2016-11-22 12:02:41

标签: ios objective-c

我正在使用以下代码将数据从一个UITableViewController发送到UIViewController,但由于某些原因我崩溃了,我不明白为什么,没有涉及NIL / NULL值。请帮我解释导致坠机的原因。

这是有问题的代码

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {  
if ([[segue identifier] isEqualToString:@"updateItem"]) {  
       NSManagedObject *selectedItem = [self.pimItems objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];  
       PimItemDetailView *destViewController = segue.destinationViewController;  
     if([NWTillHelper isDebug] == 1) {  
         NSLog(@"PimItemListView:prepareForSegue:selectedItem holds %@", selectedItem);  
         NSLog(@"PimItemListView:prepareForSegue:destViewController holds %@", destViewController);  
     }  
       destViewController.pimItem = selectedItem;  
    }  
} 

它正好在这一行崩溃

destViewController.pimItem = selectedItem;

调试告诉我我没有任何NIL / NULL值

2016-11-22 18:47:05.043 NWMobileTill[836:10726] PimItemListView:prepareForSegue:selectedItem holds <TillData: 0x6080002c3bf0> (entity: TillData; id: 0xd0000000000c0002 <x-coredata:/
    colorCode = 95;
    companyId = "BE_HM";
    discountable = 1;
    exchangeable = 1;
    itemId = 101064025138012;
    languageCode = eng;
    noos14 = "09258385254957,09258389874953";
    sizeCode = "163-012";
    status = 1;
    taxGroup = 1;
    taxRegion = BE;
    tradeItemDesc = "Jersey basic";
    withTax = 1;
})
2016-11-22 18:47:05.043 NWMobileTill[836:10726] PimItemListView:prepareForSegue:destViewController holds <PimItemDetailView: 0x7f81a1e48050>

The entire crash message is as follows, any help much appreciated.

2016-11-22 18:47:05.064 NWMobileTill[836:10726] -[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000011
2016-11-22 18:47:05.074 NWMobileTill[836:10726] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000011'
*** First throw call stack:
(
  0   CoreFoundation                      0x000000010167234b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x0000000100cb621e objc_exception_throw + 48
  2   CoreFoundation                      0x00000001016e1f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
  3   CoreFoundation                      0x00000001015f7c15 ___forwarding___ + 1013
  4   CoreFoundation                      0x00000001015f7798 _CF_forwarding_prep_0 + 120
  5   UIKit                               0x00000001025b37c7 -[UITextField _textNeedsSanitizing:] + 184
  6   UIKit                               0x00000001025b34d8 -[UITextField setText:] + 61
  7   NWMobileTill                        0x00000001006a345e -[PimItemDetailView viewDidLoad] + 1486
  8   UIKit                               0x0000000101c36c99 -[UIViewController loadViewIfRequired] + 1258
  9   UIKit                               0x0000000101c370cc -[UIViewController view] + 27
  10  UIKit                               0x00000001024fb49c -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
  11  UIKit                               0x0000000101c11932 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141
  12  UIKit                               0x0000000101c49f37 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956
  13  UIKit                               0x0000000101c4d30b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
  14  UIKit                               0x0000000101c4cdf1 -[UIViewController presentViewController:animated:completion:] + 179
  15  UIKit                               0x00000001022604f7 __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133
  16  UIKit                               0x000000010226ffbd -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447
  17  UIKit                               0x000000010226fdcd -[UIStoryboardSegueTemplate _perform:] + 82
  18  UIKit                               0x000000010227008f -[UIStoryboardSegueTemplate perform:] + 156
  19  UIKit                               0x0000000101bec52a -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1769
  20  UIKit                               0x0000000101bec78d -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 330
  21  UIKit                               0x0000000101aa22eb _runAfterCACommitDeferredBlocks + 320
  22  UIKit                               0x0000000101a8ef6f _cleanUpAfterCAFlushAndRunDeferredBlocks + 566
  23  UIKit                               0x0000000101ac03da _afterCACommitHandler + 176
  24  CoreFoundation                      0x0000000101616e17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
  25  CoreFoundation                      0x0000000101616d87 __CFRunLoopDoObservers + 391
  26  CoreFoundation                      0x00000001015fb4b6 CFRunLoopRunSpecific + 454
  27  GraphicsServices                    0x0000000105922a6f GSEventRunModal + 161
  28  UIKit                               0x0000000101a95964 UIApplicationMain + 159
  29  NWMobileTill                        0x00000001006a580f main + 111
  30  libdyld.dylib                       0x000000010383d68d start + 1
  31  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

2 个答案:

答案 0 :(得分:1)

关键信息是

  

[__ NSCFNumber rangeOfCharacterFromSet:]无法识别的选择器。

根据堆栈跟踪,错误发生在viewDidLoad的{​​{1}}中。

很可能将destViewController实例分配给文本字段的NSNumber属性。

答案 1 :(得分:0)

我不是专家,但会从这里开始:

  

0x00000001025b37c7 - [UITextField _textNeedsSanitizing:] + 184     6 UIKit 0x00000001025b34d8 - [UITextField setText:] + 61     7 NWMobileTill 0x00000001006a345e - [PimItemDetailView viewDidLoad] + 1486

查看viewDidLoad方法,看看里面发生了什么,它可能正在尝试分配一个变量(设置一个UITextField或其他)并且无法通过nil / null值或字段/来管理它它试图设置的属性实际上在对象上缺失。

再一次没有专家 - 只是粗略地看了一眼我会在哪里开始寻找。