How can I reference by code a button’s tag value which I assigned earlier?
What I’m trying to do is create a list in a table view that has checkbox images in each row. I only want one to be selected at a time within each section, so once one is selected, I would loop through the other buttons to unselect the others.
Below is the code how I assign each button in cellForRowAtIndexPath:
UIButton *addCheckButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addCheckButton.frame = CGRectMake(self.view.frame.size.width - 40.0f, 5.0f, 32.0f, 32.0f);
[addCheckButton setBackgroundImage:[UIImage imageNamed:@"checkbox_empty.png"]
forState:UIControlStateNormal];
[addCheckButton setBackgroundImage:[UIImage imageNamed:@"checkbox_full.png"]
forState:UIControlStateSelected];
[cell addSubview:addCheckButton];
[addCheckButton addTarget:self action:@selector(changeCheckState:) forControlEvents:UIControlEventTouchUpInside];
addCheckButton.tag = ([indexPath section] + 1) * 100 + [indexPath row];
I then can strip out the section and row of the selected button in my table view in the changeCheckState IBAction.
But I would also like something that I can say “Deselect buttons with tag 101, 102 and 103” within changeCheckState.
This question is one of those that are googled in seconds.