开发者

Objective c NSMutableArray removeObjectAtIndex: problem

I have a problem with removeObjectAtIndex: with a NSMutableArray. I can access to object at whatever index I want, but can not remove it.

I also read this question about removeObjectAtIndex , but this didn't solve my problem. But Diederik Hoogenboom ( https://stackoverflow.com/users/118908/diederik-hoogenboom ) asked a question in a comment, about modifying the array in another thread, which is what I am doing, 开发者_Python百科so I beleive the problem comes from there.

Any suggestions or somewhere to read from?

Thanks

Edit: Here is my code:

 NSLog(@"count = %d",[_container count]);
[_container removeAllObjects];

And what it prints:

count = 1 2011-08-15 16:33:21.838 asd[56809:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)


Given your answer to my comment, it seems like your array is just empty. As you've seen, you can't remove items from an empty array.

Edit: You've since edited your comment, so more clarification is needed. Exactly how are you determining that the length is 1 before removing an item (code please). Does the exception occur every time? Are you accessing the array from multiple threads, and if so, what is your synchronisation strategy?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜