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

  • Home
  • SEARCH
  • 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 7020465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:19:20+00:00 2026-05-27T23:19:20+00:00

I am reusing some code that build UIButtons dynamically (without interface builder). I am

  • 0

I am reusing some code that build UIButtons dynamically (without interface builder). I am using the addTarget:action:forControlEvents method to perform an action each time a button is pressed. I change the background color of the button based on the setSelected and isSelected properties.

I have added a reset button in order to deselect all buttons at once. However, I am having difficulty determining how to access the properties of a dynamically added button.

THe code to create the buttons is as follow:

for(int y = 1; y < 10; y++)
{

    for(int x = 1; x < 5; x++){
        z++;

        aButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aButton.frame = CGRectMake(x*x_plot, y_plot, 60, 40);
        [aButton setBackgroundImage:[UIImage imageNamed:@"btnUnselected.png"] forState:UIControlStateNormal];
        [aButton addTarget:self action:@selector(digitClick:) forControlEvents:UIControlEventTouchUpInside];
        [aButton setTitle:[NSString stringWithFormat:@"%d",z] forState:UIControlStateNormal];
        aButton.titleLabel.textColor = [UIColor blackColor]; 
        aButton.tag = z;
        [self.view addSubview:aButton];
    }
    y_plot=y_plot+45; //make a 4x9 grid of buttons
}
  • 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-27T23:19:21+00:00Added an answer on May 27, 2026 at 11:19 pm

    You could use code like this to go through all your subviews

    NSArray *ar = self.view.subviews;
    [ar enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj isKindOfClass:[UIButton class]])
        {
            NSLog(@"I've got 'obj' that is a UIButton on the screen!!!!");
        }
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the interest of reusing some existing code that was defined as an instance
I'm seeing a strange build bug a lot. Sometimes after typing some code we
I use some strongly-typed expressions that get serialized to allow my UI code to
I want to run some code coverage analysis (using CoverStory) on our iPhone app's
For a J2EE bean I am reusing code that was developed for a java
I'm having a really odd issue. I'm reusing a piece of code that was
I've got a problem with some legacy Java code that renders PDF files. We're
We have some code that we want to run a BULK INSERT sql command,
I'm working on getting some legacy code under test, and we're using Moq 4
I am doing some C programming for school and I have found myself reusing

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.