3
當我的NSOutlineView
項目展開時,我遇到訪問錯誤錯誤。當NSStrings
分配stringWithFormat:
時,擴展大綱時出現EXC_BAD_ACCESS
錯誤。當它們以@「string」的形式替換爲字符串時,沒有錯誤。使用NSOutlineView和stringWithFormat的EXC_BAD_ACCESS
我認爲用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;
}
嘗試添加像下面這樣的副本:return [[NSString stringWithFormat:...] copy]; – stosha
沒有骰子。這是我的第一個傾向。 – promacuser
嘗試啓用殭屍 – stosha