Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序在iPad上崩溃,但不是模拟器_Ios_Xcode_Crash_Int_Segue - Fatal编程技术网

Ios 应用程序在iPad上崩溃,但不是模拟器

Ios 应用程序在iPad上崩溃,但不是模拟器,ios,xcode,crash,int,segue,Ios,Xcode,Crash,Int,Segue,当我在iPad上运行时,我的应用程序崩溃了,但在iPad模拟器上100%工作。我在iPad上使用的是Xcode的4.6.1版和6.1.3版。 问题在于我试图在分段之间传递int的值 在我的 @property (nonatomic, assign)int currentQuestion; 在我的电脑里 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEq

当我在iPad上运行时,我的应用程序崩溃了,但在iPad模拟器上100%工作。我在iPad上使用的是Xcode的4.6.1版和6.1.3版。 问题在于我试图在分段之间传递int的值

在我的

@property (nonatomic, assign)int currentQuestion;
在我的电脑里

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"level1correct"]){
    AddLevel1IncorrectViewController *incorrect = [segue destinationViewController];
    incorrect.CQValue = self.currentQuestion;
}}
AddLevel1Incorrect.h

@property (nonatomic, assign)int CQValue;
AddLevel1Incorrect.m

@synthesize CQValue = _CQValue;

- (void)imageSelect{
int numItems = [arrayPath count];
NSMutableArray *left = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *right = [NSMutableArray arrayWithCapacity:numItems];

for (NSDictionary *itemData in arrayPath) {
    [left addObject:[itemData objectForKey:@"L"]];
    [right addObject:[itemData objectForKey:@"R"]];
}

NSLog(@" value of %d CQValue ", self.CQValue);
leftImageViewer.image = [UIImage imageNamed:left[self.CQValue]];//this is the point where the crash happens
rightImageViewer.image = [UIImage imageNamed:right[self.CQValue]];
}
有趣的是,它确实在控制台的NSLog中显示了正确的值,正如您将在崩溃消息顶部看到的那样

2013-04-03 22:50:00.404 thefyp[1506:907]  value of 1 CQValue 
2013-04-03 22:50:00.408 thefyp[1506:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
*** First throw call stack:

你知道我哪里出错了吗?

你的代码非常脆弱,这意味着它对使用的数据做了很多假设,但没有验证数据的准确性

在访问数组之前,从不检查数组的边界
self.CQValue
为1,但在本例中,数组本身为空。所以
left[self.CQValue]
left[1]
,这是无效的


检查
arrayPath
以确保它不是空的。

我应该如何使用NSLog检查它不是空的,或者它是否存在?这是否就是它崩溃的原因,因为CQValue是1,但数组是空的。由于某些原因,arrayPath没有设置。我不认为是这样,因为我在viewDidLoad中有一个函数,它再次加载数组
arrayPath=[NSArrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@“Addition1”,类型:@“plist”];[自成像选择]我创建了一个NSLog,它正确地显示了arrayPath的完整内容