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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:29:17+00:00 2026-05-31T12:29:17+00:00

i have a question view and will show 4 answers, only 1 are correct.

  • 0

i have a question view and will show 4 answers, only 1 are correct.

but i do not want the same button to be always the correct answer.

i will like to know how do i do a random placement of 4 UIButton and value every time.

enter image description here

when user go to this question again the answer will be in differ button

enter image description here

my placement of X,y,W,H

button 1
5,219,230,45

button 2
5,273,230,45

button 3
244,224,230,45

button 4
244,273,230,45

  • 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-31T12:29:18+00:00Added an answer on May 31, 2026 at 12:29 pm

    I happened to be working on a similar game app, so got some code which will definitely help. Check it out below. Note that I’ve put it in that you’d call a ‘correctAnswerMethod’ and a ‘wrongAnswerMethod’ for the correct and incorrect button clicks.

    // Define the four buttons in their respective frames, create the first button as the correct one, we'll shuffle it later.
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button1 setTitle:@"Correct Answer" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(correctAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button2 setTitle:@"Wrong Answer 1" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(wrongAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button3 setTitle:@"Wrong Answer 2" forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(wrongAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button3];
    
    UIButton *button4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button4 setTitle:@"Wrong Answer 3" forState:UIControlStateNormal];
    [button4 addTarget:self action:@selector(wrongAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button4];
    
    
    //Create an array with the rectangles used for the frames
    NSMutableArray *indexArray = [NSMutableArray arrayWithObjects:
                                  [NSValue valueWithCGRect:CGRectMake(5, 219, 230, 45)], 
                                  [NSValue valueWithCGRect:CGRectMake(5, 273, 230, 45)], 
                                  [NSValue valueWithCGRect:CGRectMake(244, 219, 230, 45)], 
                                  [NSValue valueWithCGRect:CGRectMake(244, 273, 230, 45)], nil];
    
    //Randomize the array
    NSUInteger count = [indexArray count];
    for (NSUInteger i = 0; i < count; ++i) {
        int nElements = count - i;
        int n = (arc4random() % nElements) + i;
        [indexArray exchangeObjectAtIndex:i withObjectAtIndex:n];
    }
    
    //Assign the frames
    button1.frame = [((NSValue *)[indexArray objectAtIndex:0]) CGRectValue];
    button2.frame = [((NSValue *)[indexArray objectAtIndex:1]) CGRectValue];
    button3.frame = [((NSValue *)[indexArray objectAtIndex:2]) CGRectValue];
    button4.frame = [((NSValue *)[indexArray objectAtIndex:3]) CGRectValue];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that I want to have a button that will show
Probably a stupid question, but here goes. In my view, I have the following
I have collection of Questions as List. For each question I want to show
I'm rewriting the question, as the answers so far show me that I have
Take an example of a question/answer site with a 'browse' slideshow that will show
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have a question regarding keeping the controller and view separate. It seems to
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
Question: Does Informix have a construct equivalent to Oracle's materialized view or is there
i have another (probably unanswered) question about map views. I have a map view

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.