我的应用程序在 iPad 上运行时崩溃,但在 iPad 模拟器上工作 100% 我在 iPad 上使用的是 Xcode 4.6.1 版和 6.1.3 版。问题在于我试图在 segues 之间传递 int 的值
在我的.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:
有什么想法我在这里出错了吗?