I have ten options on a view controller, each of which 'pushes' to the same new view controller displaying a specific amount of buttons (for each option a different amount of buttons may be available, ranging from 3 buttons through to 15). Currently, my code is performing similarily to the answer posted on this question.
All these buttons are created dynamically (the amount obviously depending on the length of the array) for each option using a for-loop:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if(option 1) {
Array contains different values...
}
if(option 2) {
Array contains different values...
}
etc...
for(int i = 0; i < xCoordinatePosition.count; i++) {
UIButton *imageOne = [UIButton buttonWithType:UIButtonTypeCustom];
[imageOne setTag:i];
[imageOne addTarget:self action:@selector(webViewChanged:) forControlEvents:UIControlEventTouchUpInside];
}
}
As you can see I've set a tag for each button to differentiate between the dynamically created buttons, as I want each one to display a different UIWebView
when selected.
When I've selected an option and NSLog the resulting tags of each button on a results page, I get the reply I'm after: 1, 2, 3 etc.
- (IBAction)webViewChanged:(UIButton*)sender
{
NSLog(@"%d", sender.tag);
}
The problem is, I want a unique number for each button in regard to ALL option buttons - currently each of my ten options returns with buttons that have the tags 1, 2, 3 etc. up to ten, whereas I need the first option return with 1-10, the second option return with 11-20 etc, as each individual button will be returning something unique.
For example:
Clicking the button with the tag of 7 on one option will bring up a completely different web-view to clicking on a button with the tag of 7 on another, therefore I need to make a distinction between every button.
Does anyone know how I could set the tag so that is unique for each option (instead of just setting each button of the currently chosen option to be unique like it does currently)?