Quick post on the quirkiness of the Apple SDK and the apparent lack of a checkbox control. Apple do provide button controls with 4 states that can be used for deciding logic and state.
I came across a very neat solution which uses the image object itself to make the decisions based on the current image of the control and not the various button states, which seem to involve a lot of work to achieve the same.
Here's the code: -
I came across a very neat solution which uses the image object itself to make the decisions based on the current image of the control and not the various button states, which seem to involve a lot of work to achieve the same.
Here's the code: -
-(IBAction)setFixedCategory:(id)sender{
NSLog(@"%s",__FUNCTION__);
bgImageOn = [UIImage imageNamed:@"tickedBox.png"];
bgImageOff = [UIImage imageNamed:@"tickBoxEmpty.png"];
UIButton *buttonClicked = (UIButton *)sender;
UIImage *imageOfClicked = [buttonClicked imageForState:UIControlStateNormal];
if (imageOfClicked == bgImageOff) {
[self setButtonFlags: [NSNumber numberWithInt:[sender tag]] : [NSNumber numberWithInt:1] ];
[buttonClicked setImage:bgImageOn forState:UIControlStateNormal];
} else{
[self setButtonFlags: [NSNumber numberWithInt:[sender tag]] : [NSNumber numberWithInt:0] ];
[buttonClicked setImage:bgImageOff forState:UIControlStateNormal];
}
}

Comments