【发布时间】:2013-02-25 18:49:50
【问题描述】:
我在 for 循环中遇到了问题 我将 NSArray 放入 tableview 中,我希望最后一个对象位于第一个单元格中, 但它只适用于第一个对象。
这行得通:
for(int i = 0; i < messages.count ; i++)
{
}
但这不是:
for(int i = messages.count; i > 0; i--)
{
}
错误信息是:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 203 beyond bounds [0 .. 202]'
*** First throw call stack:
(0x32bd33e7 0x3a8c4963 0x32b1eef9 0x891d3 0x34a01579 0x34a561f7 0x34a5613d 0x34a56021 0x34a55f4d 0x34a55699 0x34a55581 0x34a26561 0x349e58c7 0x34791513 0x347910b5 0x34791fd9 0x347919c3 0x347917d5 0x349eb93f 0x32ba8941 0x32ba6c39 0x32ba6f93 0x32b1a23d 0x32b1a0c9 0x366f833b 0x34a362b9 0x8549d 0x3acf1b20)
libc++abi.dylib: terminate called throwing an exception
【问题讨论】:
-
for(int i = messages.count - 1; i >= 0; i--) - 数组中的编号从零开始
标签: objective-c c for-loop nsarray