我想我会对简单的事情发疯。
以下代码:
NSLog(@"potentialPositions: %@, with count: %i", potentialPositions, [potentialPositions count]);
for (NSUInteger i = 1; i < (choices); i++) {
NSLog(@"i = %i",i);
[self drawAWord:[[currentLevel objectAtIndex:levelLink] objectAtIndex:i] atPoint:[[potentialPositions objectAtIndex:i] CGPointValue] withInitialZoom:FALSE];
}
产生以下结果:
2014-02-15 20:31:54.329 ThesaurusLinks[12446:70b] potentialPositions: (
"NSPoint: {180, 125}",
"NSPoint: {270, 200}",
"NSPoint: {350, 250}",
"NSPoint: {280, 160}"
), with count: 4
2014-02-15 20:31:54.330 ThesaurusLinks[12446:70b] i = 1
2014-02-15 20:31:54.331 ThesaurusLinks[12446:70b] i = 2
2014-02-15 20:31:54.331 ThesaurusLinks[12446:70b] i = 3
2014-02-15 20:31:54.334 ThesaurusLinks[12446:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
数组中显然有四个名为“potentialPositions”的对象。为什么它认为边界只有0..2?它不能在我的DrawAWord方法中,因为我放了一个NSLOG(结果未在上面显示)它不会被调用i = 3.我很难过。
感谢您的任何答案或提示。
答案 0 :(得分:2)
什么
[currentLevel objectAtIndex:levelLink]
返回?似乎问题在这里。添加
NSLog(@"%@",[currentLevel objectAtIndex:levelLink]);
查看它有多少元素。
答案 1 :(得分:1)
你想从0开始:
for (NSUInteger i = 0; i < (choices); i++)