Possible Duplicate:
Objective-C NSMutableArray mutated while being enumerated?删除对象
我用这个代码在索引中删除一个对象:
-(IBAction)deleteMessage:(id)sender{
UIButton *button = (UIButton*) sender;
for (UIImageView *imageView in imageArray)
{
if ([imageView isKindOfClass:[UIImageView class]] && imageView.tag == button.tag)
{
if (imageView.frame.size.height == 60) {
x = 60;
}
if (imageView.frame.size.height == 200) {
x = 200;
}
for (UITextView *text in messagetext)
{
for (UITextView *name in messagename)
{
if ([text isKindOfClass:[UITextView class]] && text.tag == button.tag && text.tag== name.tag)
{
[imageView removeFromSuperview];
[messagename removeObjectAtIndex:button.tag - 1];
[messagetext removeObjectAtIndex:button.tag - 1];
}
}
}
的错误是:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x704bdb0> was mutated while being enumerated.'
我注意到的是,如果我删除第一数组中的最后一个对象,并按顺序从最后到冷杉,它的工作原理。但如果我尝试这是不是最后,应用程序崩溃,并给出了错误的索引处移除对象:(1,2,3,4..I删除对象2 ...崩溃了...如果我删除对象4没有崩溃)
OK感谢这个工作得很好,顺便我我们ARC – Alessandro 2012-07-12 18:11:19