Souli
Souli

Reputation: 21

Why simulator iPhone/iPad are given different results vs iPhone Retina(4-inch) and iPhone Retina(4-inch 64-bit)

This is my first time to ask questions because I am new here. Thanks very much for answering! I appreciate for your time.

Using Xcode 5.1.1

Here is my problem, when testing on simulator or actual devices, the result comes out different. See screenshot attached on food image. When i test on simulator iPhone Retina(4-inch 64-bit), the result is correct, food image displays correctly and matching with text.

When i test on simulator iPhone Retina(4-inch), the result is incorrect, food image displays does not match with text.

I also test actual devices, like iPad Air displays correct but iPad3 is incorrect. Food image displays not matching with text.

Can you help me out how to solve this issue? I do not understand why same code but it generates different result.

for (NSUInteger i=0; i<30; i++)

{
    UIImage *anImage = [UIImage imageNamed:[NSString stringWithFormat:@"food%d.jpg", (int)i+1]];

    [arrimagefood addObject:anImage];
}
[ArrforAllDicFood addObjectsFromArray:[DictionaryForEnglishFood allKeys]];
[TableForFood reloadData];

Code moved and formatted from multiple comments:

- (void)viewDidLoad {
    [super viewDidLoad]; DictionaryForEnglishFood=[[NSMutableDictionary alloc]init];
    DictionaryForLaoFood=[[NSMutableDictionary alloc]init];
    DictionaryForPythnFood=[[NSMutableDictionary alloc]init];
    DictionaryForImageFood=[[NSMutableDictionary alloc]init];
    DictionaryForAudioFood=[[NSMutableDictionary alloc]init];
    ArrforAllDicFood=[[NSMutableArray alloc]init];
    arrimagefood=[[NSMutableArray alloc]init];

    // add English German food
    //    [DictionaryForEnglishFood setValue:@"Asparagus" forKey:@"food1"];//5
    //    [DictionaryForEnglishFood setValue:@"Lobscouse" forKey:@"food2"];//29
    //    [DictionaryForEnglishFood setValue:@"Sauerkraut" forKey:@"food3"];//22
    //    [DictionaryForEnglishFood setValue:@"Potatoes" forKey:@"food4"]; //16
    //    [DictionaryForEnglishFood setValue:@"Pumpkin bread" forKey:@"food5"];//11
    //    [DictionaryForEnglishFood setValue:@"Asparagus Sauce" forKey:@"food6"];//6
    //    ......

    // Add German words
    //    [DictionaryForLaoFood setValue:@"Spargel" forKey:@"food1"];//5
    //    [DictionaryForLaoFood setValue:@"Labskaus" forKey:@"food2"];//29
    //    [DictionaryForLaoFood setValue:@"Sauerkraut" forKey:@"food3"];//22
    //    [DictionaryForLaoFood setValue:@"Pellkartoffeln" forKey:@"food4"]; //16
    //    [DictionaryForLaoFood setValue:@"Kürbisbrot" forKey:@"food5"];//11
    //    [DictionaryForLaoFood setValue:@"Spargelsoße" forKey:@"food6"];//6
    //    ........

    // Add German pronounciation
    //    [DictionaryForPythnFood setValue:@"Shpahrg-uhl" forKey:@"food1"];//5
    //    [DictionaryForPythnFood setValue:@"Lahbs-cows" forKey:@"food2"];//29
    //    [DictionaryForPythnFood setValue:@"Sour-krout" forKey:@"food3"];//22
    //    [DictionaryForPythnFood setValue:@"Pehl-car-tohf-ehln" forKey:@"food4"]; //16
    //    [DictionaryForPythnFood setValue:@"Koorb-is-broht" forKey:@"food5"];//11
    //    [DictionaryForPythnFood setValue:@"Shpahrg-uhl-sohs-uh" forKey:@"food6"];//6
    //    ......

    // Add German audio
    //    [DictionaryForAudioFood setValue:@"aspargus" forKey:@"food1"];//5
    //    [DictionaryForAudioFood setValue:@"lobscouse" forKey:@"food2"];//29
    //    [DictionaryForAudioFood setValue:@"sauerkraut" forKey:@"food3"];//22
    //    [DictionaryForAudioFood setValue:@"potatoes" forKey:@"food4"]; //16
    //    [DictionaryForAudioFood setValue:@"pumpkin bread" forKey:@"food5"];//11
    //    [DictionaryForAudioFood setValue:@"aspargus sauce" forKey:@"food6"];//6
    //    ....

    for (NSUInteger i=0; i<30; i++) {
        UIImage *anImage = [UIImage imageNamed:[NSString stringWithFormat:@"food%d.jpg", (int)i+1]];
        [arrimagefood addObject:anImage];
    }
    [ArrforAllDicFood addObjectsFromArray:[DictionaryForEnglishFood allKeys]];
    [TableForFood reloadData];
}


-(UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([[ UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
        static NSString *CellIdentifier = @"CustomCellPlace";
        CustomCellPlace *cell= (CustomCellPlace) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //  create a uitableviewcell
    //  if(cell == nil) {
    //      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellPlace" owner:self options:nil];
    //      for (id currentObject in topLevelObjects) {
    //          if ([currentObject isKindOfClass:[UITableViewCell class]]) {
    //              cell = currentObject;
    //          }
    //      }
    //  }

        cell.tag=indexPath.row;
        cell.backgroundColor = [UIColor clearColor];
        cell.backgroundView = [UIView new] ;
        cell.selectedBackgroundView = [UIView new] ;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;


        cell.lb1.text=[DictionaryForEnglishFood objectForKey:[ArrforAllDicFood objectAtIndex:indexPath.row]];
        cell.lb2.text=[DictionaryForLaoFood objectForKey:[ArrforAllDicFood objectAtIndex:indexPath.row]];
        cell.lb3.text=[DictionaryForPythnFood objectForKey:[ArrforAllDicFood objectAtIndex:indexPath.row]];
        for(int i=0; i<[arrimagefood count];i++) {
            NSUInteger str=indexPath.row;
            cell.imageview.image=[arrimagefood objectAtIndex:str];
        } return cell;
    }
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [ArrforAllDicFood count];
}

The problem is here when testing simulator iPhone(4 inch) or actual devices like iPhone5, the result(text) does not order/match with food image but running with simulator iPhone(4 inch 64-bit) is matched/order with food image. So How can I change the code in order to make it works both with iPhone(4 inch) and iPhone(4 inch 64-bit).

Food image displays order from 1-30 but only text is changed somehow which i have no clue what to do. Thanks again.

iPhone Retina(4-inch 64-bit) iPhone Retina(4-inch)

Upvotes: 2

Views: 161

Answers (1)

zaph
zaph

Reputation: 112855

Dictionaries do not have an order so the `allKeys' method can return any order. It is not even guaranteed that the order will be same from one call to another. Adding, removing or changing an entry can also result in a different order being returned.

What you need to do is include the image name (or name index) with the food names all in one structure. Relying on order is not a good solution.

The Simulator is just that, it runs code that is compiled for the Intel processor simulation the device. The device code is compiled for the ARM processor. One can expect differences such as you are seeing as any order of keys is correct.

An Emulator runs the other processors code by emulating the same instructions and the result would be the same order on each device but again in any order.

Upvotes: 1

Related Questions