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

  • Home
  • SEARCH
  • 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 8922285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:47:40+00:00 2026-06-15T06:47:40+00:00

EDIT: All array used in my project are NSMutableArray class An overview of what

  • 0

EDIT: All array used in my project are NSMutableArray class

An overview of what I want to do is from my selectClueView, user can select a number from 3-10. Which represent the number of clue they will play. It will then generate list of random number between 0 and the objectArray.count and add the NSNumber into another array known as dataArray. Everything is working fine including prepareForSegue which transfer SelectClueViewController.dataArray to GamePageViewController.clueToSelect

However, I am stuck with loading data into the new array ds, from an array that hold all the object allDataObject. I am fairly new to iOS and because I had a working function in c#, I tried to replicate it in objective-C, unfortunately it seems that I can’t replicate it fully.

In short, I’m trying to add data from allDataObject array into ds array with NSNumber values from cluesToSelect array.

Below are the coding which are used. Any help to fix the issue would be much appreciated. If there are any more information that I should give, please let me know.

SelectClueViewController.m

- (IBAction)onGoPress:(id)sender {
    [self chooseNumber];
     NSLog(@"Array got %d numbers",dataArray.count);
}

-(void)chooseNumber
{
    [dataArray removeAllObjects];
    maxCount = [numberOfClues.text intValue];

    int count = 0;
    do {

        NSInteger rdmNumber = arc4random()%objectArray.count;
        if (![dataArray containsObject:[NSNumber numberWithInt:rdmNumber]])
        {
            NSNumber* number = [NSNumber numberWithInt:rdmNumber];
            [dataArray addObject:number];
            count++;
            NSLog(@"random no - %d",rdmNumber);
        }
    } while (count < maxCount);

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"sendNumber"]) {


        GamePageViewController *gpViewController = [segue destinationViewController];
        gpViewController.cluesToSelect = self.dataArray;
        NSLog(@"Success");
    }
}

GamePageViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    daoDS = [[ClueDataDAO alloc]init];
    self.allDataObject = daoDS.PopulateDataSource;
    NSLog(@"%d",cluesToSelect.count);

    [self fillDataSample];

    //for keyboard
    self.answer.delegate = self;        
}

    -(void)fillDataSample
{
    int count = 0;
    do {
       // [self.ds addObject:[allDataObject objectAtIndex:[[cluesToSelect objectAtIndex:count]intValue] ]];
        ds = [[NSMutableArray alloc]init];
        currentClueData = [[ClueData alloc]init];        
        int firstIndex = [[cluesToSelect objectAtIndex:count]intValue];
        currentClueData = [allDataObject objectAtIndex:firstIndex];
        [ds addObject:currentClueData];

        count++;
    } while (count < cluesToSelect.count);
    NSLog(@"ds got %d object",ds.count);
}

EDIT:

I am now able to make it add in object into the ds array, unfortunately it only add once. Can someone look at my fillDataSample function?

  • 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-15T06:47:41+00:00Added an answer on June 15, 2026 at 6:47 am

    The reason as to why it didn’t work for my new method of loading object from allClueData to a class object currentClueData to ds was because I did not nil and alloc init the class object after adding it to ds. The object were unable to overwrite their own value like they do in other language. (which was probably why I’m wrecking my brain for doing it in objective C) But after adding in nil the object and casting alloc and init, its working great now. thanks all 🙂

    -(void)fillDataSample
    {
    int count = 0;
    currentClueData = [[ClueData alloc]init];
    ds = [[NSMutableArray alloc]init];
    do {
    // [self.ds addObject:[allDataObject objectAtIndex:[[cluesToSelect objectAtIndex:count]intValue] ]];

        int firstIndex = [[cluesToSelect objectAtIndex:count]intValue];
        currentClueData = [allDataObject objectAtIndex:firstIndex];
        [ds addObject:currentClueData];
        currentClueData =nil;
        currentClueData = [[ClueData alloc]init];
    
    
        count++;
    } while (count < cluesToSelect.count);
    NSLog(@"ds got %d object",ds.count);
    

    }

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

Sidebar

Related Questions

Who can post an example of asihttprequest used on wordpress post? EDIT I want
I have this function to edit all fields that come from the form and
EDIT: I where provided several interfaces that describe all the functionality that the project
I want to edit all buttons with a specific tag. I have tagged each
EDIT: after reading all the input from the other users, i decided, to use
I am working on a feature to edit all the items in the table.
I am using a nested model form to edit all phone numbers of a
EDIT: I have fixed all but two warnings now, so thank you all for
*edit: I understand that stackoverflow has banned all questions regarding using Microsoft's Visio. I'm
EDIT I've just started skimming Codd's famous 1970 paper that started it all, that

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.