objective c - How to check state of NSCheckbox create programitically in cocoa -


i created mutiple checkbox dynamic, want check state of them don't know how that. code create mutiple nscheckbox:

for(int i=1; i<=number;i++) {      deletecheckbox= [[nsbutton alloc] initwithframe:nsmakerect (20,textfield_y,50,25)];     [deletecheckbox setbuttontype:nsswitchbutton];     [deletecheckbox setbezelstyle:0];     [deletecheckbox settitle:@""];     [deletecheckbox settag:200+i];     [deletecheckbox setstate:nsoffstate];     [deletecheckbox setaction:@selector(checkstate:)];     [guiview addsubview:deletecheckbox];     [deletecheckbox release]; } 

and below code check state:

    -(ibaction)checkstate:(id)sender {     if ([deletecheckbox state] == nsonstate) {          nslog(@"selected");     }     else {          nslog(@"not selected");      } } 

but when run, printf: "not selected". can me? in advance

updated: new problem:

i have new problem, created checkbox dynamic , set tag it. want check if checked, add tag nsarray. used code add array:

    -(ibaction)checkstate:(nsbutton *)sender {     if ([sender state] == nsonstate) {         nslog(@"selected");         (int = 1; <=  number; ++) {             [deleteselectedarray addobject: [[guiview viewwithtag:200+i] intvalue]];          }         nslog(@"deleteselectedarray : %@",deleteselectedarray);      }     else {         nslog(@"not selected");     } } 

please me more? much

you have check state of sending button, not of instance variable deletecheckbox (which has been released , not point valid button):

-(ibaction)checkstate:(nsbutton *)sender {     if ([sender state] == nsonstate) {         nslog(@"selected");     }     else {         nslog(@"not selected");     } } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -