0

我已经这样做了:

那是具有两列的 NSOutlineView,第一列是 TextCell,在第二列上我拖放复选框单元格。现在,我将所有行设置为 true:

-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *) tableColumn byItem:(id)item {
    if ([[tableColumn identifier] isEqualToString:@"name"]) {
        返回[项目名称];
    } else if ([[tableColumn identifier] isEqualToString:@"sel"]) {
        返回@“1”;//对于NSOnState
                //返回@“0”;//对于 NSOffState
    }
}

现在我希望当用户单击复选框时它转到 NSOffState 并且我尝试内部方法:

-(void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {

    [项目 setSel:NSOffState];
}

但它不去,我该怎么办?

帮我 !!!

4

1 回答 1

0
    #进口

    @interface AppDelegate : NSObject {
        NSMutableArray *array;
    }

    @property (assign) IBOutlet NSWindow *window;

    @结尾
    #import "AppDelegate.h"

    @implementation AppDelegate

    @synthesize 窗口 = _window;

    - (void)dealloc
    {
       [超级释放];
    }

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        // 在此处插入代码以初始化您的应用程序
    }

    -(void)awakeFromNib
    {
        数组=[[[NSMutableArray alloc]init]autorelease];
        NSMutableDictionary *dc=[NSMutableDictionary 字典];

        布尔测试=是;
        NSNumber *num=[NSNumber numberWithBool:test];

        [dc setObject:num forKey:@"sel"];
        [dc setObject:@"name" forKey:@"name"];

        [数组添加对象:dc];
    //[self setArray:self.array];
     }

     - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
     {
        返回 [数组 objectAtIndex:index];
     }


     - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
     {
        返回否;
     }

     - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
     {
        返回[数组计数];
     }

     - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
     {
        if ([[tableColumn 标识符] isEqualToString:@"name"])
     {
        /*
        NSString *str=[item objectForKey:@"name"];
        NSLog(@"name=%@",str);*/
        返回@“名称”;//str;
     }
        else if ([[tableColumn identifier] isEqualToString:@"sel"])
       {
        /*
        NSString *str=[item objectForKey:@"sel"];
        NSNumber *num=[NSNumber numberWithBool:[str boolValue]];
        NSLog(@"sel=%@",num);*/
        返回@“0”;//数字;
       }
     别的
         {
         返回零;
         }
     }
     - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
     {
       [item setValue:object forKey:[tableColumn identifier]];
     }

     @结尾
于 2013-09-25T18:46:54.497 回答