Programmatically linked buttons

I am designing an app that requires me to have a grid of buttons each with four different states. Unselected, Selected, Hit, or Miss. I am trying to generate these buttons programatically but I am having trouble having just one of them remain selected. Is there a way that maybe I could put them into an array and then iterate over the array to unselect them? I looked into IBOutletCollections but those will not work because I want to create these buttons programmatically


I think maybe you should check this demo I've learned in Developing iOS 7 Apps for iPhone and iPad cs193p.

This worked for me where _lastSelectedButton is the id of the last selected button and the width is 25

    //Unselect the last selected button However only change its background if is blue
    [[_lastSelectedButton layer] setBorderWidth:0.0f];
    if([_lastSelectedButton.titleLabel.text  isEqual: @"0"]){

        [[_lastSelectedButton layer] setBackgroundColor:[missColor CGColor]];
    }else if([_lastSelectedButton.titleLabel.text  isEqual: @"/"]){
        [[_lastSelectedButton layer] setBackgroundColor: [hitColor CGColor]];
        [[_lastSelectedButton layer] setBackgroundColor:unselectedColor.CGColor];
_lastSelectedButton = nil;

- (void)advanceSelection:(UIButton*)sender


int i = 0;
//Find the indice that the present selected thing is
for( UIButton *button in btnList )
    if( sender == button )
        if((i >= (self.numberOfPlayers - 1) * width) &&(( i + 1) % 5 == 0)){
            //Then animated scroll to the next frame
            if (i + 1 == self.numberOfPlayers * width) {
                //then it is the last button
                [self unselect];

                CGFloat x = (([_pageControl currentPage] + 1.0 ) * 320.0);
                [_scrollView setContentOffset:CGPointMake(x, 0.0f) animated:YES];
                [self selection:btnList[i - (width * (self.numberOfPlayers - 1)) + 1]];
                [self scrollViewDidEndDecelerating:self.scrollView];
                self.pageControl.currentPage = _pageControl.currentPage + 1;
        }else if(i >= ((self.numberOfPlayers - 1) * width)){
            //We want to move it up one
            //subtract width times hieght and ad one
            [self selection:btnList[i - (width * (self.numberOfPlayers - 1)) + 1]];

            //To go one down add 25 (the width)
            [self selection:btnList[i + 25]];

Need Your Help

d3 c3: adding svg element to c3 chart

d3.js svg c3.js

I'm trying to place an svg element on a c3 chart such that it aligns horizontally with one of the tick marks.