Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 833487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:31:32+00:00 2026-05-15T04:31:32+00:00

I have a bunch of buttons named: button1 button2 button3 etc. Is there a

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:31:33+00:00Added an answer on May 15, 2026 at 4:31 am

    In objective C you can put the elements in an NSArray, and more generally for any language, put the elements you want to iterate over in a collection.

    If you really want to do cute things with dynamic names, use an NSDictionary and look it up by a string name; this is pretty much what PHP does with its $$foo syntax anyway.

    #import <Foundation/Foundation.h>
    
    int
    main()
    {
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
      id button1 = @"this is button 1";// not actually buttons, but same principle
      id button2 = @"this is button 2";
      id button3 = @"this is button 3";
    
      NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                         button1, @"button1",
                         button2, @"button2",
                         button3, @"button3"];
    
      int i;
      for (i = 1; i <= 3; ++i) {
        // you can send messages to these objects instead of NSLogging them
        NSLog([dict objectForKey: [NSString stringWithFormat:@"button%d", i]]);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of inputs and buttons, similar to how Facebook's news feed:
say I have a bunch of radio buttons in an html form. How do
So I am having this problem wit my download link. Basically my previous way
I have a bunch of radio buttons, and depending on the choices of other
I have a bunch of radio buttons, and I have a <br/> after each
Does Java and/or Spring have the concept of properties? I have bunch of domain
I have a bunch of files that I need to be able to transport
I have a bunch of latitude/longitude pairs that map to known x/y coordinates on
I have a bunch of .NET frameworks installed on my machine. I know that
I have a bunch of classes I want to rename. Some of them have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.