سؤال

I am getting trouble in one of my app . I have 36 images & 36 sound and 36 text this all name are same now i want to Declare array of this all means array of images array of text and array of sound and now randomly want to display 9 images from this on button tag and on same page 9 sound play one bye one with text and identify that image.

so here i declare images array and also array of text i also done arc4random and getting images but now the problem is how i can use dictionary over here so that i can store the data in this dictionary so how i can do this plz help me ontis.

هل كانت مفيدة؟

المحلول

You should create an array of dictionary objects, with each dictionary object containing one image, one sound and one text object (the same name ones). So the array will contain 36 dictionary objects and each dictionary object will contain 3 objects each.

NSMutableArray *combinedArray = [[NSMutableArray alloc] init];
for(i=0;i<36;i++) {
    NSDictionary *dict = [[NSDictionary dictionaryWithObjectsAndKeys:[imageArray objectAtIndex:i], @"image", [textArray objectAtIndex:i], @"text", [soundArray objectAtIndex:i], @"sound", nil]];
    [combinedArray addObject:dict];
}

Now you can use arc4Random on the combinedArray, and you'll have all the 3 corresponding objects at the selected random index. Hope this helps

نصائح أخرى

if you want to store array into dictinoary then write below code.What you do is create 3 different array and then create for loop.

          for(int i=0;i<some value:i++)
          {
            dictMut=[[NSMutableDictionary alloc]init];
            [dictMut setObject:[dataArrayA objectAtIndex:w] forKey:@"A"];
            [dictMut setObject:[dataArrayB objectAtIndex:w] forKey:@"B"];
            [dictMut setObject:[dataArrayC objectAtIndex:w] forKey:@"C"];
          }

let me know it is working or not!!!

Happy Coding!!!!

ok i saw that...Now what you did is you have created textarray, soundarray and imagearray.

Now after create these 3 arrays write code like below..

        for(int i=0;i<36:i++)
      {
        dictMut=[[NSMutableDictionary alloc]init];
        [dictMut setObject:[textarray objectAtIndex:w] forKey:@"A"];
        [dictMut setObject:[soundarray objectAtIndex:w] forKey:@"B"];
        [dictMut setObject:[imagearray objectAtIndex:w] forKey:@"C"];
      }

and your array values will be stored in dictionary.

let me know it is working or not!!!!

HaPPY Coding!!!!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top