I created Multiple checkbox dynamic and set tag for it, Now I want to check if it checked, add its tag to NSArray.
This is my code to 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];
}
I used this code but it add all to Array:
-(IBAction)checkState:(NSButton *)sender
{
if ([sender state] == NSOnState) {
NSLog(@"selected");
for (int i = 1; i <= number; i ++) {
[deleteSelectedArray addObject: [[guiView viewWithTag:200+i] intValue]];
}
NSLog(@"deleteSelectedArray : %@",deleteSelectedArray);
}
else {
NSLog(@"not selected");
}
}
How can I do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…