このコードを使用して、インデックスのオブジェクトを削除します。
-(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 delete object2... crash...if I delete object 4 noクラッシュ)