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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:54:30+00:00 2026-05-25T05:54:30+00:00

I have an array holding other arrays, but cant get this to work!! IM

  • 0

I have an array holding other arrays, but cant get this to work!! IM trying to pull string values from subArrays I can access first the first subarray no problem but then when i try changing the label to the object in second array my prog crashes anyidea on how i should approach this?

int count = 0; // variable to access the required sub array 
NSArray* myArray; // array holding other arrays 
UILabel* mylabel; // label to display my string values from the array s

-(void) setLabel 
{

    NSArray* subArray = [myArray objectAtIndex: count];
    [myLabel setText:[subArray objectAtIndex:1]]; // this works fine
}

-(void) changeLabelToNextArray
{
    count ++
    [self setLabel]; //program crashes here when try to load label from next array 
} 
  • 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-25T05:54:30+00:00Added an answer on May 25, 2026 at 5:54 am

    Why are you doing this?

    [myLabel setText:[subArray objectAtIndex:1]];
    

    This will crash if

    1. subArray does not have an object at index 1
    2. the object at index 1 cannot be set as the label text (i.e cannot be made a string)

    I think some more information on how your arrays are structured would help give a better answer to what the problem is.

    EDIT (Based on comments below)
    Try this:

    NSArray* myArray;   // Contains 5 subarrays, each containing 5 strings
    
    UILabel* myLabel1;
    UILabel* myLabel2;
    UILabel* myLabel3;
    UILabel* myLabel4;
    UILabel* myLabel5;
    
    int count = 0;      // Keeps track of which subarray we are on
    
    - (void)setLabel
    {
        NSArray* subArray = [myArray objectAtIndex:count];
        [myLabel1 setText: [subArray objectAtIndex:0]]
        [myLabel2 setText: [subArray objectAtIndex:1]]
        [myLabel3 setText: [subArray objectAtIndex:2]]
        [myLabel4 setText: [subArray objectAtIndex:3]]
        [myLabel5 setText: [subArray objectAtIndex:4]]
        count = (count + 1) % 5;    // Ensures that count is always 0 to 4
    }
    

    Now whenever you call setLabel, the text should change on all 5 of your labels provided you do indeed have 5 strings in each of the 5 subarrays.

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

Sidebar

Related Questions

I have an array controller holding some values, say - subjects. I am displaying
I have a json array which is holding the correct string independent of language
I have a multi-dim string array something like this:- string[,] names = new string[2,
Right now I have a 2d string array holding my data: //...find number of
I have an array of objects that looks like this: [#<Holding id: 5, user_id:
Often, I will have an array holding a set of values each of which
I have a main object. It holds a lot of arrays holding other objects.
I have an array holding values and that array is in a session. I
I have an array holding this data: Array ( [1402377] => 7 [1562441] =>
Say I have an array of arbitrary size holding single characters. I want to

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.