我现在正在学习核心数据,我已经完成了第一部分,但是当我尝试将教授保存在下一个表格视图中时,我得到了一个 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)