gpt4 book ai didi

iphone - 为什么模拟器 iPhone/iPad 与 iPhone Retina(4 英寸)和 iPhone Retina(4 英寸 64 位)的结果不同

转载 作者:行者123 更新时间:2023-12-03 21:15:03 26 4
gpt4 key购买 nike

这是我第一次提问,因为我是新来的。非常感谢您的回答!感谢您抽出时间。

使用Xcode 5.1.1

这是我的问题,在模拟器或实际设备上测试时,结果不同。请参阅食物图像上所附的屏幕截图。当我在模拟器iPhone Retina(4英寸64位)上测试时,结果是正确的,食物图像显示正确并且与文本匹配。

当我在模拟器iPhone Retina(4英寸)上测试时,结果不正确,食物图像显示与文本不匹配。

我还测试了实际设备,例如 iPad Air 显示正确,但 iPad3 不正确。食物图像显示与文本不匹配。

你能帮我解决这个问题吗?我不明白为什么相同的代码但会产生不同的结果。

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];

从多个注释中移动并格式化代码:

- (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];
}

问题出在测试模拟器 iPhone(4 英寸)或实际设备(如 iPhone5)时,结果(文本)与食物图像不排序/匹配,但使用模拟器 iPhone(4 英寸 64 位)运行时匹配/排序与食物图像。那么我如何更改代码才能使其同时适用于 iPhone(4 英寸)和 iPhone(4 英寸 64 位)。

食物图像显示从 1-30 的顺序,但只有文本以某种方式发生了变化,我不知道该怎么做。再次感谢。

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

最佳答案

字典没有顺序,因此“allKeys”方法可以返回任何顺序。甚至不能保证一次调用的顺序与另一次调用的顺序相同。添加、删除或更改条目也可能导致返回不同的订单。

您需要做的是将图像名称(或名称索引)与食物名称全部包含在一个结构中。依赖顺序并不是一个好的解决方案。

模拟器就是这样,它运行为英特尔处理器模拟设备而编译的代码。设备代码是针对 ARM 处理器编译的。正如您所看到的,人们可以预见到差异,因为任何键顺序都是正确的。

模拟器通过模拟相同的指令来运行其他处理器代码,结果在每个设备上的顺序相同,但顺序任意。

关于iphone - 为什么模拟器 iPhone/iPad 与 iPhone Retina(4 英寸)和 iPhone Retina(4 英寸 64 位)的结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25366619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com