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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:47:20+00:00 2026-06-04T16:47:20+00:00

else if (setIndexPath == 4) { viewWithButtons.frame = CGRectMake(5, 40, 310, 390); int ch

  • 0
else if (setIndexPath == 4)
{
    viewWithButtons.frame = CGRectMake(5, 40, 310, 390);

    int ch = 6;
    int cv = 6;

    for ( int i = 0 ; i < cv ; ++i )
    {
        for ( j = 0 ; j < ch ; ++j )
        {
            btnMatrix = [[[UIButton alloc] initWithFrame:CGRectMake(10+pw*j, 51+ph*i, width, height)] autorelease];
            btnMatrix.tag = i*ch+j;
            btnMatrix.userInteractionEnabled = TRUE;
            [btnMatrix addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchDown];
            [btnMatrix setBackgroundImage:imgDefaultBG forState:UIControlStateNormal];

            [viewWithButtons addSubview:btnMatrix];

            [arrButton addObject:btnMatrix];
        }
    }
}
[self.view addSubview:viewWithButtons];

I am generating buttons dynamically according to the selected matrix, like 4 * 4, 4 * 5, 4 * 6, 5 * 6, 6 * 6 etc….

Buttons are completely set as per the selected matrix from above (the code is for 6 * 6 matrix).

Now i have to set random background images of these buttons.

I am not able to set this kind of dynamic buttons’ background.

is there any effective way to set backgrounds dynamically in random order for each separate buttons?

    for (intimg = 1; intimg <= 15; intimg++)
    {
        arr_FirstSet = [[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:@"%d_f_2.png",intimg], nil];
    }
    for (intimgSET2 = 1; intimgSET2 <= 15; intimgSET2++) {
        arr_SecondSet = [[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:@"%d_s_2.png",intimgSET2], nil];
    }

I am adding images in this format to the NSMutableArray.

How to pick random image from the above used arrays. I have to match both arrays images & give the result on buttons. If both matches, suppose i press on one button it will display 1_f_2.png & on another button press it will display 1_s_2.png (as background)then both of these buttons will be removed from the view.

I had tried many logics to get this.

I am not getting exactly what i am interested to do on touchdown of button.

Please suggest any code snippet or link or code also.

Thanks in advance.

  • 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-04T16:47:22+00:00Added an answer on June 4, 2026 at 4:47 pm
    - (UIImage*)randomImage {
        NSInteger imageCount = [[self imageArray] count]
        return [[self imageArray] objectAtIndex:arc4random() % imageCount]; 
    }
    

    If you want matching pairs. Use dictionary with two images, or simple class holding two images.

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

Sidebar

Related Questions

Possible Duplicate: else or return? Consider a typical recursive function: public int Fact(n) {
Someone else with the same problem still didn't get a decent answer/fix for my
Has anyone else had this issue and found a working solution? I've enabled the
has anyone else experienced this . I have SP1 but i have to kill
Has anyone else experienced this? I have uninstalled and reinstalled TortoiseSVN as well as
Has anybody else noticed that Bindings with ElementName do not resolve correctly for MenuItem
I am debugging someone else's work and the solution is quite large. When I
I have an if else tree that is going to grow as I add
I wonder if anyone else is facing the same issue. I have a UITextView
Searched SO and Everywhere else, including the .net developers guide to directory services programming

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.