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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:00:46+00:00 2026-06-05T23:00:46+00:00

Here is my piece of code that creates buttons programmatically: NSArray *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@Cover_0.png],

  • 0

Here is my piece of code that creates buttons programmatically:

NSArray *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@"Cover_0.png"],
                      [UIImage imageNamed:@"Cover_1.png"],
                      [UIImage imageNamed:@"Cover_2.png"],
                      [UIImage imageNamed:@"Cover_3.png"],
                      [UIImage imageNamed:@"Cover_4.png"],
                      [UIImage imageNamed:@"Cover_5.png"],
                      [UIImage imageNamed:@"Cover_6.png"],
                      [UIImage imageNamed:@"Cover_7.png"],nil];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200.0f, 200.0f);
[button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];

[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return button;

But while running it I can’t get in simulator and its throwing a Signal Sigabart error.
Can anyone help?

  • 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-05T23:00:47+00:00Added an answer on June 5, 2026 at 11:00 pm

    To create buttons programmatically using array of selectors you can use this snippet of code:

    //define Strategy

    @interface DataItemStrategy : NSObject
    @property(nonatomic, assign) SEL someSelector;
    @end
    
    @implementation DataItemStrategy
    
    @synthesize someSelector = _someSelector;
    
    -(id)initWithSelector:(SEL)someSelector
    {
        self = [super init];
        if (self)
        {
            self.someSelector = someSelector;
        }
        return self;
    }
    
    @end
    
    
    -(void)createButtons
    {
        NSArray *buttonImages =[NSArray arrayWithObjects:[UIImage imageNamed:@"Cover_0.png"],
                              [UIImage imageNamed:@"Cover_1.png"],
                              [UIImage imageNamed:@"Cover_2.png"],nil];
    
        NSArray *dataStrategies = [NSArray arrayWithObjects:
                                       [[[DataItemStrategy alloc] initWithSelector:@selector(buttonAction0:)] autorelease],
                                       [[[DataItemStrategy alloc] initWithSelector:@selector(buttonAction1:)] autorelease],
                                       [[[DataItemStrategy alloc] initWithSelector:@selector(buttonAction2:)] autorelease], nil];
    
        CGRect buttonFrame = CGRectMake(0, 0, 50, 50);
        for (NSInteger i = 0; i < [buttonImages count]; i++)
        {
            buttonFrame.origin.y += 50;
            UIImage *buttonImage = [buttonImages objectAtIndex:i];
            DataItemStrategy *dataStrategie = [dataStrategies objectAtIndex:i];
            NSString *title = [NSString stringWithFormat:@"%d", i];
            UIButton *button = [self buttonWithFrame:buttonFrame image:buttonImage action:dataStrategie.someSelector title:title];
            [self.view addSubview:button];
        }    
    }
    
    -(UIButton *)buttonWithFrame:(CGRect)buttonFrame image:(UIImage *)buttonImage action:(SEL)buttonAction title:(NSString *)title
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = buttonFrame;
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
    
        [button setImage:buttonImage forState:UIControlStateNormal];
        [button addTarget:self action:buttonAction forControlEvents:UIControlEventTouchUpInside];
        return button;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the piece of code that I have used for Java 5.0 TreeSet<Integer>
Here's a piece of code that takes most time in my program, according to
I have a piece of code here that does not work despite me using
I've been here and accordingly found out that this piece of code here var
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
Recently I found a piece of code that creates an instance of TButton from
I have a piece of code that creates a UNIX domain socket using IO::Socket::UNIX
I have a piece of code that creates dynamic controls using 2 while loops.
my first question here! I have a problem with a piece of code that
I'm think something like Facebook apps here. User generated pieces of code that people

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.