Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 利用核心数据获取sigabrt错误_Objective C - Fatal编程技术网

Objective c 利用核心数据获取sigabrt错误

Objective c 利用核心数据获取sigabrt错误,objective-c,Objective C,我正在学习关于核心数据的知识,我已经记下了第一部分,但是当我试图在下一个表视图中保存教授时,我得到了一个signbrt错误。错误发生在第8行 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

我正在学习关于核心数据的知识,我已经记下了第一部分,但是当我试图在下一个表视图中保存教授时,我得到了一个signbrt错误。错误发生在第8行

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return [(NSSet *)[department valueForKey:@"Professors"] count]; // uses the department's 
    // "Professors" relationship to get the number of professors in the department entity  
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ProfessorCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    NSManagedObject *professor = [[self sortProfessors] objectAtIndex:indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", 
                           [[professor valueForKey:@"FirstName"] description], 
                           [[professor valueForKey:@"LastName"] description]];
    cell.detailTextLabel.text = [[professor valueForKey:@"EMail"] description];
    return cell;
}
这是我运行应用程序后打印的文字

2012-04-24 17:43:08.808 BlahBlah[2905:b603] Department Saved in the persistent data store
2012-04-24 17:43:08.812 BlahBlah[2905:b603] -[NSManagedObject count]: unrecognized selector sent to instance 0x5a84a70
2012-04-24 17:43:08.815 BlahBlah[2905:b603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject count]: unrecognized selector sent to instance 0x5a84a70'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00fa35a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x010f7313 objc_exception_throw + 44
    2   CoreFoundation                      0x00fa50bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00f14966 ___forwarding___ + 966
    4   CoreFoundation                      0x00f14522 _CF_forwarding_prep_0 + 50
    5   BlahBlah                            0x00005423 -[ProfessorListViewController tableView:numberOfRowsInSection:] + 115
    6   UIKit                               0x001db2b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
    7   UIKit                               0x001d8d88 -[UITableViewRowData numberOfRows] + 108
    8   UIKit                               0x0008c677 -[UITableView noteNumberOfRowsChanged] + 132
    9   UIKit                               0x00099708 -[UITableView reloadData] + 773
    10  BlahBlah                            0x00005212 -[ProfessorListViewController viewWillAppear:] + 146
    11  UIKit                               0x000d8210 -[UINavigationController viewWillAppear:] + 334
    12  UIKit                               0x002ce8e4 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 6192
    13  UIKit                               0x000d3385 -[UIViewController _dismissModalViewControllerWithTransition:from:] + 2058
    14  UIKit                               0x000cfeb8 -[UIViewController dismissModalViewControllerWithTransition:] + 940
    15  BlahBlah                            0x000060d8 -[ProfessorDataEntryController save:] + 648
    16  UIKit                               0x0001e4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    17  UIKit                               0x000ae799 -[UIControl sendAction:to:forEvent:] + 67
    18  UIKit                               0x000b0c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    19  UIKit                               0x000af7d8 -[UIControl touchesEnded:withEvent:] + 458
    20  UIKit                               0x00042ded -[UIWindow _sendTouchesForEvent:] + 567
    21  UIKit                               0x00023c37 -[UIApplication sendEvent:] + 447
    22  UIKit                               0x00028f2e _UIApplicationHandleEvent + 7576
    23  GraphicsServices                    0x011dc992 PurpleEventCallback + 1550
    24  CoreFoundation                      0x00f84944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    25  CoreFoundation                      0x00ee4cf7 __CFRunLoopDoSource1 + 215
    26  CoreFoundation                      0x00ee1f83 __CFRunLoopRun + 979
    27  CoreFoundation                      0x00ee1840 CFRunLoopRunSpecific + 208
    28  CoreFoundation                      0x00ee1761 CFRunLoopRunInMode + 97
    29  GraphicsServices                    0x011db1c4 GSEventRunModal + 217
    30  GraphicsServices                    0x011db289 GSEventRun + 115
    31  UIKit                               0x0002cc93 UIApplicationMain + 1160
    32  BlahBlah                            0x00001ba9 main + 121
    33  BlahBlah                            0x00001b25 start + 53
)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb) 

看看你的模型,确保“教授”被宣布为系里的一对多关系