I have this method here:
- (IBAction)checkBoxTapped:(id)sender forEvent:(UIEvent*)event
{
NSLog(@"%@", sender);
}
this is what sender is returning...
My question is how do I get the value of _checked
Checkbox is a class
Please Help
I have this method here:
- (IBAction)checkBoxTapped:(id)sender forEvent:(UIEvent*)event
{
NSLog(@"%@", sender);
}
this is what sender is returning...
My question is how do I get the value of _checked
Checkbox is a class
Please Help
Without seeing the interface we can only guess what the getter method is for that property. As it's BOOL
, and following convention, it's probably called isChecked
as it's probably declared as:
@property (readonly, getter=isChecked) BOOL checked;
Therefore, simply access the isChecked
method (the NSAssert()
is entirely optional):
NSAssert([sender isKindOfClass:[Checkbox class]], @"Expected a Checkbox instance");
Checkbox *checkbox = (Checkbox *)sender;
if (checkbox.isChecked) {
// Do thing
}
You can replace id with Checkbox class in a method signature like that:
- (IBAction)checkBoxTapped:(Checkbox *)sender forEvent:(UIEvent*)event {
NSLog(@"%@", sender.checked ? @"Checked" : @"Not checked");
}
Probably, you are not going to connect this method to another control that is not a Checkbox.
Also you need to move checked
property to header file (public interface) of Checkbox class