当我的一个项目展开时,我遇到了错误的访问错误NSOutlineView
。用NSStrings
分配时stringWithFormat:
,EXC_BAD_ACCESS
展开大纲时出错。当它们替换为@"string"形式的字符串时,没有错误。
我认为 ARC 正在发布某些内容,但我不知道如何防止它发生。这里有什么不合适的地方?
-(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
if(!item)
return [_characterList count];
else if( [item isKindOfClass:[Character class]] )
return 3;
return 0;
}
-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
if( [item isKindOfClass:[Character class]] )
return YES;
return NO;
}
-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
if (!item)
return (Character*)[_characterList objectAtIndex:index];
else {
NSLog(@"%@", item);
Character *characterItem = (Character*)item;
switch (index) {
case 0:
return [NSString stringWithFormat:@"Api key: %@", [characterItem apiKey]];
break;
case 1:
return [NSString stringWithFormat:@"Access Mask: %@", [characterItem mask]];
break;
case 2:
return @"Last Updated: today";
break;
default:
break;
}
}
return nil;
}
-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if([item isKindOfClass:[Character class]])
return [(Character*)item name];
else
return item;
return nil;
}