0
當我在iPad上運行它時,我的應用程序崩潰,但在iPad模擬器上運行100%我在iPad上使用Xcode和V6.1.3的版本4.6.1。 問題在於哪裏,我試圖通過塞格斯應用程序崩潰在iPad上,但不是模擬器
之間的整型值在我的.h
@property (nonatomic, assign)int currentQuestion;
在我的.m
- (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:
任何想法上看到我錯了嗎?
我應該如何檢查它不是空的與NSLog或如果它存在? – user2236306 2013-04-03 22:08:04
這會是它崩潰的原因嗎 – user2236306 2013-04-03 22:46:37
它崩潰了,因爲CQValue是1但數組是空的。出於某種原因,arrayPath沒有被設置。 – 2013-04-03 23:04:15