我做到了:
这是NSOutlineView有两列,第一列是TextCell,第二列是我拖放Check Box Cell。 现在,我将所有行设置为true:
-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *) tableColumn byItem:(id)item { if ([[tableColumn identifier] isEqualToString:@"name"]) { return [item name]; } else if ([[tableColumn identifier] isEqualToString:@"sel"]) { return @"1"; //for NSOnState //return @"0"; //for NSOffState } }
现在我希望当用户点击复选框时,它会转到NSOffState并尝试使用内部方法:
-(void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { [item setSel:NSOffState]; }
但它不去,我该怎么办?
帮助我!!!
答案 0 :(得分:0)
#import @interface AppDelegate : NSObject { NSMutableArray *array; } @property (assign) IBOutlet NSWindow *window; @end
#import "AppDelegate.h" @implementation AppDelegate @synthesize window = _window; - (void)dealloc { [super dealloc]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application } -(void)awakeFromNib { array=[[[NSMutableArray alloc]init]autorelease]; NSMutableDictionary *dc=[NSMutableDictionary dictionary]; BOOL test=YES; NSNumber *num=[NSNumber numberWithBool:test]; [dc setObject:num forKey:@"sel"]; [dc setObject:@"name" forKey:@"name"]; [array addObject:dc]; //[self setArray:self.array]; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { return [array objectAtIndex:index]; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { return NO; } - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { return [array count]; } - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { if ([[tableColumn identifier] isEqualToString:@"name"]) { /* NSString *str=[item objectForKey:@"name"]; NSLog(@"name=%@",str);*/ return @"name"; //str; } else if ([[tableColumn identifier] isEqualToString:@"sel"]) { /* NSString *str=[item objectForKey:@"sel"]; NSNumber *num=[NSNumber numberWithBool:[str boolValue]]; NSLog(@"sel=%@",num);*/ return @"0"; //num; } else { return nil; } } - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { [item setValue:object forKey:[tableColumn identifier]]; } @end