Can I access elements/methods named "button1" "button2" "button3" etc. using "buttoni" inside a for-

Posted by cksubs on Stack Overflow See other posts from Stack Overflow or by cksubs
Published on 2010-06-09T05:09:55Z Indexed on 2010/06/09 5:12 UTC
Read the original article Hit count: 210

I have a bunch of buttons named:

button1
button2
button3
etc.

Is there a way to basically do this?

pseudocode
for(int i = 1, i < 15, i++) {
    button{i}.selected = YES;
}

This also goes for method calls, etc. I've often thought such a way of calling methods would be very convenient, but I don't think I've ever seen it done when using compiled languages. But I have done it using PHP.

Is there any way to do this in Objective-C? (That's where my problem is now, but I'd also be interested in if you can do this in other languages.) Alternately, is there a reason why this is NOT a good way to go about accessing all the UI elements?

Thanks!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about object-oriented-design