xcode - OSX Cocoa NSButton type checkbox " Select all " issue, and how to solve it? -
xcode - OSX Cocoa NSButton type checkbox " Select all " issue, and how to solve it? -
i have multiple checkboxes in table view. , out of table, have 1 checkbox action select looks this:
- (ibaction)selectall:(nsbutton *)sender { (int = 0; < [maintable numberofrows]; i++) { nstablecellview *cellview = [maintable makeviewwithidentifier:@"maincell" owner:self]; for(nsbutton *button in cellview.subviews){ //i have multiple buttons, need 1 tooltip if([[button tooltip] isequaltostring:@"select"]){ [button setstate:sender.state]; } } } }
that code works great view not updated. tried [maintable reloaddata]
guess not that.
simple question how update view?
i tried:
1) creating new nsbutton , replacing old 1 no luck there. view not updated.
2) trying create nsbuttons dynamically instead of using designer , applying code, no luck there. unusual also. when created dynamically elements in cellview subviews ones created designer.
3) [button setneedsdisplay:yes]
not work;
i not experienced mac programmer.
update
-(nsview *)tableview:(nstableview *)tableview viewfortablecolumn:(nstablecolumn *)tablecolumn row:(nsinteger)row{ nsdictionary *flag = [emails objectatindex:row]; nsstring *identifier = [tablecolumn identifier]; if([identifier isequaltostring:@"maincell"]){ nstablecellview *cellview = [tableview makeviewwithidentifier:@"maincell" owner:self]; [cellview.textfield setstringvalue:flag[@"subject"]]; cellview.textfield.drawsbackground = yes; [cellview.textfield setbackgroundcolor:[nscolor whitecolor]]; //[cellview setbackgroundstyle:no]; nsbutton *checkbox; nsrect frame_checkbox = nsmakerect(7, 35 , 317, 20); checkbox = [[nsbutton alloc] initwithframe:frame_checkbox]; //nslog(@"message id: %@", flag[@"id"]); [checkbox setbuttontype:nsswitchbutton]; [checkbox setobjectvalue:flag[@"id"]]; [checkbox setstate:no]; [checkbox settitle:@""]; [checkbox settooltip:@"select message id"];
i got :
if([flag[@"ischecked"] boolvalue] == 1){ [checkbox setstate:yes]; } else{ [checkbox setstate:no]; } [cellview addsubview:checkbox]; //other subview shere homecoming cellview; } homecoming nil; }
this part of code adding subviews.
new update
nsmutablearray *emails; emails = [[nsmutablearray alloc] init]; [emails addobject:@{@"id":@"1", @"from":@"some name", @"subject":@"some subject", @"email":@"some email", @"date":@"10 min ago", @"ischecked":@no}];
since nsmutablearray not have addobject. in order addobject this: nsmutablearray *emails
has nsmutabledictionary *emails
have no thought how addobject nsmutabledictionary;
if like:
for(nsmutabledictionary *dict in emails){ nslog(@"%@", dict); [dict setobject:@"1" forkey:@"ischecked"]; }
i getting error:
[__nsdictionaryi setobject:forkey:]: unrecognized selector sent instance
assuming emails
info source:
nsdictionary *flag = [emails objectatindex:row];
flag
dictionary @ indexpath.
you need modify emails holds value checkbox within of viewfortablecolumn
do:
[checkbox setstate:flag[@"ischecked"] ? nsoffstate : nsonstate];
and check them all:
- (ibaction)selectall:(nsbutton *)sender { nsmutablearray *emailcopy = [[nsmutablearray alloc]init]; for(nsdictionary *dict in emails){ nslog(@"dict = %@", dict); nsmutabledictionary *newdict = [[nsmutabledictionary alloc] init]; [newdict addentriesfromdictionary:dict]; [newdict setobject:@"1" forkey:@"ischecked"]; [emailcopy addobject:newdict]; nslog(@"newdict = %@", newdict); } emails = emailcopy; [tableview reloaddata]; }
xcode osx cocoa
Comments
Post a Comment