这样的代码运行起来会出现崩溃
//targetButton
for (UIButton * button in self.selectedBtnArr)
{
if (targetButton.tag == button.tag)
{
[self.selectedBtnArr removeObject:button];
}
}
在对可变数据类型如字典、数组,进行快速遍历的时候,是不可以对其增、删操作。否则就会引起“<__NSArrayM:XXXXXX> was mutated while being enumerated.”的崩溃。
It is not safe to modify a mutable collection while enumerating through it. Some enumerators may currently allow enumeration of a collection that is modified, but this behavior is not guaranteed to be supported in the future.
解决方案:
//targetButton
for (UIButton * button in self.selectedBtnArr)
{
if (targetButton.tag == button.tag)
{
[self.selectedBtnArr removeObject:button];
break;
}
}
网友评论