Cocoa 自定义NSMangeObject访问器崩溃NSOutlineView
我认为这是核心数据中的一个bug,但在我提交bug报告之前,我想确定这不仅仅是我的愚蠢 我设置了一个NSOutlineView来访问5个不同核心数据实体的数据。每个实体的数据都通过绑定到实体及其“ManagedObjectContext”的不同NSArrayController进行访问。然后,我让NSOutlineViewDataSource方法根据展开的实体返回正确的NSString对象 注:实体在别处声明为NSArray,并带有实体名称Cocoa 自定义NSMangeObject访问器崩溃NSOutlineView,cocoa,core-data,nsmanagedobject,nsarraycontroller,nsoutlineview,Cocoa,Core Data,Nsmanagedobject,Nsarraycontroller,Nsoutlineview,我认为这是核心数据中的一个bug,但在我提交bug报告之前,我想确定这不仅仅是我的愚蠢 我设置了一个NSOutlineView来访问5个不同核心数据实体的数据。每个实体的数据都通过绑定到实体及其“ManagedObjectContext”的不同NSArrayController进行访问。然后,我让NSOutlineViewDataSource方法根据展开的实体返回正确的NSString对象 注:实体在别处声明为NSArray,并带有实体名称 - (id)outlineView:(NSOutlin
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index
ofItem:(id)item {
if(nil == item) {
return [entities objectAtIndex:index];
}
NSInteger entityIdx = [entities indexOfObject:item];
if (entityIdx == NSNotFound) {
return @"";
}
id returnObject = @"";
switch (entityIdx) {
case 0: {
Person *person = [[peopleArrayController arrangedObjects] objectAtIndex:index];
returnObject = person.fullName;
break;
}
case 1: {
Media *media = [[mediaArrayController arrangedObjects] objectAtIndex:index];
returnObject = media.imageTitle;
break;
}
case 2: {
Note *note = [[notesArrayController arrangedObjects] objectAtIndex:index];
returnObject = note.noteDescription;
break;
}
case 3: {
Source *source = [[sourcesArrayController arrangedObjects] objectAtIndex:index];
returnObject = source.title;
break;
}
case 4: {
Repository *repo = [[repostioriesArrayController arrangedObjects] objectAtIndex:index];
returnObject = repo.name;
break;
}
default:
break;
}
return returnObject;
}
Person实体属性fullName和Media实体属性imageTitle是自定义访问器
- (NSString *)fullName {
[self willAccessValueForKey:@"surName"];
[self willAccessValueForKey:@"givenName"];
NSString *firstName = [self valueForKey:@"givenName"];
NSString *lastName = [self valueForKey:@"surName"];
NSString *string = [NSString stringWithFormat:@"%@ %@", (firstName) ? firstName : @"", (lastName) ? lastName : @""];
[self didAccessValueForKey:@"surName"];
[self didAccessValueForKey:@"givenName"];
return string;
}
}
当我试图展开人物或媒体实体时,程序正在崩溃,但当我展开其他实体时,程序没有崩溃。我将崩溃跟踪到[NSCell\u setContents:][NSObject(NSObject)doesNotRecognizeSelector:]
我将要返回的媒体属性更改为标准核心数据访问器属性@“path”,扩展媒体实体时程序停止崩溃。因此,问题肯定与自定义访问器有关
仅供参考-我检查以确保实体设置为使用NSManagedObject类
除了一个bug,谁能给我一个崩溃的原因吗?我通过改变方法解决了这个问题
-(id)outlineView:(NSOutlineView*)outlineView子项:(NSInteger)项的索引:(id)项
返回托管对象的步骤
case 1: {
Media *media = [[mediaArrayController arrangedObjects] objectAtIndex:index];
returnObject = media;
break;
}
那我有办法了
-(id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)tableColumn by item:(id)item
返回字符串
if ([item isKindOfClass:[Media class]]) {
Media *media = (Media *)item;
return media.imageTitle;
}
它没有与行returnObject=media.path崩溃;但它确实在returnObject=[media.path lastPathComponent]行中崩溃了;
if ([item isKindOfClass:[Media class]]) {
Media *media = (Media *)item;
return media.imageTitle;
}