uibuttonsender-id

Change UIButton highlight via ID


I've currently got a method that allows the user to press on a button and it sets its state to isSelected = YES, the title of this button is then appended to an NSString. If the user then presses the button again the title is removed from the string and the button isSelected = NO.

Any button connected to this method will succesfully add and remove text from said string. This is being done in the method via:

UIButton *tempbutton = (UIButton *)sender;

I then get the title from this tempButton and append to a string. Now i have many buttons the user can press on in this menu but what i'd like to be able to do is loop through all the buttons in the view and set their isSelected = NO. I'd like to be able to do this without having to setup property / synthesize for every button.

Is this possible, i can post the code i have tried shortly, but if there is a standard way of doing this it would be great.


Solution

  • Ok i figured it out, i simply hooked up each UIButton in the storyboard to a single Outlet Collection (new referencing outlet collection) and then looped through the array setting the buttons selected state.

    // remove button highlights
    for (int i =0; i<[quickNotesCollection count]; i++){
    [[quickNotesCollection objectAtIndex:i]setSelected:NO];
    }
    

    Hope this helps anyone else with a similar issue, second time i have answered my own question :)