NSTableView错误:preparedCellAtColumn:row:被调用

时间:2013-12-28 18:02:48

标签: macos cocoa nsoutlineview

我遇到一个问题,当您在NSOutlineView中选择顶级对象时,会生成一条错误消息:

  

“基于视图的NSTableView错误:preparedCellAtColumn:row:已被调用。请记录此日志中的回溯错误,或停止使用该方法。”

我正在使用的NSOutlineView设置为View Based。我不知道为什么甚至调用preparedCellAtColumn方法。我添加了该方法并放置了一个断点来尝试跟踪调用它的内容,但是当XCode触发此异常时,它看起来阻止了它的执行。

编辑 - 委托和日期源方法

- (BOOL) itemAtIndexIsHeader: (NSInteger) index
{
    return [self isHeader: [_projectPane itemAtRow: index]];
}
- (BOOL) isHeader: (id) item
{
    return [item isKindOfClass: [Folder class]];
}
- (BOOL) outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
{
    return NO;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
    //item is nil when the outline view wants to inquire for root level items
    if (item == nil)
        return [[[PMDataManager sharedManager] allFolders] objectAtIndex: index];
    else{
        Folder *folder = (Folder *) item;
        return [[[folder projects] allObjects] objectAtIndex: index];
    }
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
    return [self isHeader: item];
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
    if (item == nil) { //item is nil when the outline view wants to inquire for root level items
        return [[[PMDataManager sharedManager] allFolders] count];
    }
    else if ([self isHeader: item]) {
        Folder *folder = (Folder *) item;
        return [[[folder projects] allObjects] count];
    }

    return 0;
}
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
    if ([self isHeader: item]){
        PMProjectHeaderCell *cell = [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];
        Folder *folder = (Folder *) item;
        [[cell headerText] setStringValue: [folder name]];

        return cell;
    }
    else{
        PMProjectCell *cell = [outlineView makeViewWithIdentifier:@"ProjectCell" owner:self];
        Project *project = (Project *) item;
        [[cell projectNameTextField] setStringValue: [project name]];
        return cell;
    }

    return nil;
}
- (void) outlineViewSelectionDidChange:(NSNotification *)notification
{
    selectedProjectIndex = [_projectPane selectedRow];
    [self reloadRightPane];
    [self refresh: nil];
}

1 个答案:

答案 0 :(得分:0)

验证您的表视图内容模式是否与您尝试使用的数据源/委托方法匹配。

如果您尝试使用基于单元格的数据源,请验证表格视图内容模式是否为"基于单元格"。基于视图也是如此。