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 8090093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:36:16+00:00 2026-06-05T19:36:16+00:00

this is the way I create and add subviews into a view. I’m wondering

  • 0

this is the way I create and add subviews into a view.

I’m wondering why the count always returns 0, when it should return “hundreds”. What am I doing wrong, thanks!

I have added more code where shows clearly my issue. I copy/pasted all functions involved on my initial question.

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];

        [self.contenedor addSubview:vistaPanelBotones];
        [self crearBotones];
    }

    - (void) crearBotones {
    UIColor *colores[] = {
        [UIColor blueColor],
        [UIColor brownColor],
        [UIColor redColor],
        [UIColor orangeColor],
        [UIColor greenColor],     
        [UIColor yellowColor],
        [UIColor purpleColor],
        [UIColor blackColor],
        [UIColor whiteColor],
        [UIColor darkGrayColor],
        [UIColor magentaColor],
        [UIColor cyanColor],
    };

    int indice = 0;
    for (int col = 0; col < self.vistaPanelBotones.frame.size.width ; col=col+20) {
        for (int fila = 0; fila < self.vistaPanelBotones.frame.size.height-20 ; fila = fila+20) {

            CGRect frame = CGRectMake(col, fila, 20, 20);

            Boton *boton = [Boton new];
            boton.frame = frame;
            boton.layer.backgroundColor = colores[(fila + col) % 7].CGColor;
            boton.layer.cornerRadius = 0.25;
            boton.layer.borderWidth = 0.25;
            boton.layer.borderColor = [UIColor whiteColor].CGColor;
            boton.layer.delegate = self;
            [self.vistaPanelBotones addSubview:boton];
            [boton setNeedsDisplay];    
        }
        indice++;
    }   
    NSLog(@"Vista Botones SubViews:%i",[[self.vistaPanelBotones subviews] count]); 

}

- (IBAction)reiniciar:(id)sender {

    if (self.vistaPanelBotones == nil){
        NSLog(@"no existe la vista"); 
    }
    NSUInteger count = self.vistaPanelBotones.subviews.count;
    NSLog(@"Vista SubViews: %i",count); 

}
  • 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-06-05T19:36:18+00:00Added an answer on June 5, 2026 at 7:36 pm

    Here are a few of my thoughts:

    1. I would check if self.vistaPanelBotones is non-nil, just in case (if it were nil, you would not get any errors in that code, but also no subviews).
    2. Possibly executing this before you have a valid frame (IIRC, viewWillAppear is the earliest callback with valid geometry)
    3. I’m pretty sure if boton was nil you would get an exception when adding as a subview, but it’s another test worth using for debugging.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created this regular expression to validate names: ^[a-zA-Z0-9\s\-\,]+.\*?$ Is there a way add
At the moment I write stored procedures this way: create proc doStuff @amount int
Is this the only way to create custom model validation? To do it using
I followed this way. To create a workspace to manage your source-controlled files 1.
This looks simple but I am confused: The way I create a vector of
What is the easiest way to create a HashMap like this : ( student1
Is there any way to create a property like this C# property in Objective-C?
Is there a way to create a condition like this? @products = Product.find(:all, :limit
What's the most efficient way to create this simple array dynamically. var arr =
what is a convenient way to create a directory when a path like this

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.