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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:40:07+00:00 2026-05-29T07:40:07+00:00

I know there are some questions on here that are very much like this

  • 0

I know there are some questions on here that are very much like this but I am not finding the info I need. I am adding a grid of UIButtons to my view in a for loop. Each time a new button is created, I call addTarget:self action:@selector(doYourThing:) forControlEvent:UIControlEventTouchUpInside. If I only make one button, it works. But when I create a whole grid of buttons using the for loop, none of the buttons want to call the selector and instead I get EXC_BAD_ACCESS. Any suggestions? Thanks everyone.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [titleLabel setText:[site title]];
    // Do any additional setup after loading the view from its nib.
    buttonArray = [[NSMutableArray alloc] initWithCapacity:250];
    int i = 0;
    int c = 0;
    int index = 0;
    for (c=0; c < [site columnCount]; c++) {
    for (i = 0; i < [site rowCount]; i++) {
        plotButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [plotButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        CGPoint origin = CGPointMake(60.0, 40.0);
        [plotButton setTitle:@"Plot" forState:UIControlStateNormal];
        [plotButton setFrame:CGRectMake(origin.x + (90.0 * c), origin.y + (45.0 * i), 90.0, 45.0)];
        [plotButton setTag:index];
        [buttonArray insertObject:plotButton atIndex:index];
        NSLog(@"%d", [plotButton tag]);
        index ++;
        [[self view] addSubview:plotButton];

        }
    }
}

Here’s my for loop. idk if it’s dumb to nest them like that but I’m making a grid of buttons and that seemed the sensible way to get rows and columns done. Anyways, thanks.

Added exception breakpoint. Got: Catchpoint 2 (throw)Pending breakpoint 1 – “objc_exception_throw” resolved.

  • 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-29T07:40:08+00:00Added an answer on May 29, 2026 at 7:40 am

    Your code works fine when I replace [site columnCount] and [site rowCount] by an integer. My guess is that you have a problem in one of those two methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are already some similar questions here. But I do not want
I know there have been some similar questions to this, but they haven't helped
I do know some basic differences but there are still some questions in my
I know there are already some posts about this topic, but I cannot find
I know that there are some threads have a similar issue with this thread.
i know that there is some rules and standards in css handling but i
I know there is some syntax with ? to optionally render attribute. But I
Simple query, possibly impossible but I know there are some clever people out there
I understand there are many questions related to this, so I'll be very specific.
First of all, I know there are a few other StackOverflow questions about 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.