objective c - NSButtonCell NSSwitchButton doesn't display checked box -
the nsbuttoncell
code bellow works fine, doesn't visualy display check icon when clicked. ideas why?
- (nscell *)outlineview:(nsoutlineview *)outlineview datacellfortablecolumn:(nstablecolumn *)tablecolumn item:(id)item { if ([[tablecolumn identifier] isequaltostring:@"select"]) { nsbuttoncell *cell = [[nsbuttoncell alloc]init]; [cell setbuttontype:nsswitchbutton]; [cell settarget:self]; [cell setaction:@selector(checkboxchanged:)]; [cell settitle:@""]; return cell; } else { nscell *cell = [tablecolumn datacell]; return cell; } }
here action code:
- (ibaction)checkboxchanged:(id)sender { nsbuttoncell *acell = [[sender tablecolumnwithidentifier:@"select"] datacellforrow:[sender selectedrow]]; if ([acell state] == nsonstate) { nslog(@"on"); [acell setstate:nsoffstate]; } else { nslog(@"off"); [acell setstate:nsonstate]; } }
i'm not sure why first solution didn't work—maybe didn't have delegate hooked up? note data source , delegate 2 separate things.
the method implemented in answer, data source, not proper place that. data source, , particularly numberofrowsintableview:
, tableview:objectvaluefortablecolumn:row:
, should only return content being presented, not create view/cell objects.
i recommend creating and configuring nsbuttoncell in xib, if have one, or in same place create table view , columns—that's correct place set each column's cell.
Comments
Post a Comment