开发者

About NSMutableArray objectAtIndex

Is the objectA开发者_如何学JAVAtIndex start with 1 instead of 0? I use the objectAtIndex , and passing data 0, but it said that this is out of bound. So, I guess that is start at 1, am I right?


It starts at 0. If you got an exception, it's because the array was empty. You have to add something to the array first before it has any contents. Use addObject: to put items into it. Use count to find out how many items are currently in it.


NSMutableArray is zero-indexed. However; from the docs:

If index is beyond the end of the array (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.

If there is nothing stored in the array, accessing index 0 will fail the above test, and cause the error.


No, it starts with 0.

Make sure your array is populated though. If the array is empty, you can't use -objectAtIndex: with any indices, since there's no way to return something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜