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 に答える
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 に答える