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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:34:15+00:00 2026-06-08T16:34:15+00:00

Hello all! I am very new to xcode and objective-c but I have been

  • 0

Hello all! I am very new to xcode and objective-c but I have been programming in C# for a long time. I am just starting out with Xcode and I have been tasked with making an app and I am lost!

I have 5 UILabels and an array with 5 values, I would like the UILabels to randomly load a value from the array until all values from the array are used.

I can make Dynamic Labels but its a pain to get them lined up correctly which I will do if needed, but I am not sure how to do that with objective-c(In C# its easy).

Thanks!

  • 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-08T16:34:16+00:00Added an answer on June 8, 2026 at 4:34 pm

    Hey there and welcome to SO, this is a great place to help you learn XCode and Objective-C.

    There is a couple ways that you could do this, so I’ll just give you one example solution.

    You can actually create your labels in your NIB(.xib) file, and then link them to variables in your code, that way you can easily access them without having to create them programatically. The way that you would do this is as follows:

    ViewController.h
    
    @interface ViewController : UIViewController
    {
        //Some Variables
    }
    
    @property (nonatomic, strong) NSMutableArray *stringValues;
    
    @property (nonatomic, strong) IBOutlet UILabel *randLabel1;
    @property (nonatomic, strong) IBOutlet UILabel *randLabel2;
    @property (nonatomic, strong) IBOutlet UILabel *randLabel3;
    @property (nonatomic, strong) IBOutlet UILabel *randLabel4;
    @property (nonatomic, strong) IBOutlet UILabel *randLabel5;
    

    The key here is that the labels are declared is IBOutlets in your .h file. This allows you to then go into your .xib file and link the labels you’ve positioned to the variables in the code. To link a label, press and hold your control key, and then drag it to your viewcontroller and release, you should see a menu that lists your 5 labels and then you can select the appropriate one.

    As for then selecting a random string to load into the label, you could that in the following way.

    ViewController.m 
    
    
    -(void)selectLabelValue: 
    {
        for(int i = 5; i > 0; i--)
        {
            randIdx = arc4random() % i;
            switch (i):
            case 1:
                Label1.text = [stringValue objectAtIndex:randIdx];
                [stringValue removeObjectAtIndex:randIdx];            
            case 2:
                Label2.text = [stringValue objectAtIndex:randIdx];
                [stringValue removeObjectAtIndex:randIdx];  
            case 3:
                Label3.text = [stringValue objectAtIndex:randIdx];
                [stringValue removeObjectAtIndex:randIdx];  
            case 4:
                Label4.text = [stringValue objectAtIndex:randIdx];
                [stringValue removeObjectAtIndex:randIdx];  
            case 5: 
                Label5.text = [stringValue objectAtIndex:randIdx];
                [stringValue removeObjectAtIndex:randIdx];  
            default:
                NSLog(@"Error, index out of bounds, there is no label for this value!";
    }
    

    The idea with the above is that you iterate through your 5 labels, and as you do you randomly generate an index to select your string to load. After you load the string you remove it from the possible strings so that you dont get duplicates. I would double check the function names for the array manipulation because I did those off of the top of my head, so I’m not 100% sure they are correct, but something that does what they should do does exist.

    Anyways, I hope that helps, if you have questions leave a comment and I’ll do my best to answer it.

    EDIT: Just in case someone is skimming and doesn’t read the comment by Richard. He brings up a valid point that using a switch statement in the above was is bad design, and should be handled using an array, while programatically creating the labels. This way you can easily just select the label you want via the array index. It is a significantly cleaner solution, and preferable to the above. The only reason it was done with switches is that this way you don’t have to create the labels through code which was the preference of user1221399, so keep this in mind.

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

Sidebar

Related Questions

Hello to all, Double d = 1.000000000000000000000000000000001; System.out.println(d); The code above prints 1.0 but
I'm Very new to Objective-C iPhone programming. I'm kinda gonna go with the trial-and-error
For a long time now I have been searching through the forum whilst teaching
Hello all I have some very important system files which I want to protect
hello all i am working on a project in which i have a webpage
hello all I have a small dialog which I created dynamically, which has a
hello all this seems to be my problem I have a table in mysql
Problem Hello all! I have this code which takes my jpg image loops through
Hello all and thanks for your time reading this. I need to verify certificates
hello all i am using this code to show flip animation...... i have a

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.