3

使用基于视图时如何更改所选行的视图NSTableView?具体来说,我想为未选中的行创建一个简单的 NSView 子类,为选中的行创建一个更复杂的 NSView 子类,它允许编辑与行项目相关的更多信息。

例如,Things 允许您扩展正在编辑的项目,如下所示:http: //culturedcode.com/things/

4

3 回答 3

3

我的猜测是你想在选择行时使用不同的 NSTableCellView 子类。我认为你应该能够做这样的事情:

- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
    NSTableView *table = [notification object];
    NSIndexSet *allColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[table tableColumns] count])];
    [table reloadDataForRowIndexes:[table selectedRowIndexes] columnIndexes:allColumns];
}

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    if ([[tableView selectedRowIndexes] containsIndex:row])
    {
        // If the row is selected, return an instance of the class for selected views
        SelectedTableCellView *selectedView = ...; // Get from makeViewWithIdentifier:
        // Set up selectedView
        return selectedView;
    }
    else 
    {
        NonSelectedTableCellView *nonSelectedView = ...; // Get from makeViewWithIdentifier:
        // Set up nonSelectedView
        return nonSelectedView;
    }
}
于 2012-04-09T18:38:54.413 回答
1

如果您详细说明“将视图更改为更复杂的视图”的含义,那可能会很好

尽管如此,您可以例如- (void)tableViewSelectionDidChange:(NSNotification *)notification在表格视图的委托中实现,NSTableRowView如果它是可见的,则获取选定的,并以您想要的方式更改它,包括使其更复杂,扩展它(见下文)等。

要修改行的大小,您需要- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row在同一个委托中实现,并调用表视图-noteHeightOfRowsWithIndexesChanged来更新特定行的高度。

于 2012-04-09T18:26:07.787 回答
0

我认为该应用程序是NSOutlineView在大纲视图中创建的,只有您可以轻松扩展您选择的行...

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{        


    if ([item isKindOfClass:[NSDictionary class]]) 
    {
        return YES;        
    }else 
    {
        return NO;
    }
}

我认为这种方式是写..

于 2012-08-29T12:58:24.133 回答