Use IBOutletCollection to add an outlet collection to your view controller, like this:
@property (retain, nonatomic) IBOutletCollection(UIButton) NSMutableSet* buttons;
This will let you connect all your buttons to one outlet. The property buttons
will be a NSMutableSet containing all your buttons. You can continue to identify individual buttons using the button's tag
property. This is handy if you want to iterate through all your buttons, perhaps to set up each button's image:
for (UIButton *b in self.buttons) {
b.imageView.image = [self imageForTag:b.tag];
}
(You'll need to supply the -imageForTag:
method to provide the right image for a given tag, or find some other way to map from tags to images.)
Of course, if you already know the range of tag values for all your buttons, and if you've taken care to make the tags unique inside the view containing all the buttons, you can also just fetch each button individually using -viewWithTag:
. This is probably not as fast as having the whole set of buttons already created, as you have with the outlet collection described above, but it does mean that there's one less thing to maintain.