gpt4 book ai didi

ios - 应用程序崩溃并出现异常 : *** Collection was mutated while being enumerated

转载 作者:行者123 更新时间:2023-12-03 00:55:56 24 4
gpt4 key购买 nike

应用程序崩溃并出现异常:

 *** Collection  was mutated while being enumerated.2016-01-25 08:55:30.606 Mink Chatter[416:70120] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection  was mutated while being enumerated.'*** First throw call stack:(0x1821c5900 0x181833f80 0x1821c5334 0x186ead9f0 0x186ead7d8 0x186ead6d8 0x1001a6834 0x10015ddc0 0x100905bf0 0x100905bb0 0x100914e10 0x1009144d8 0x181e2d470 0x181e2d020)libc++abi.dylib: terminating with uncaught exception of type NSException

Code:

self.refreshIndicators = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < 3; i++) {
UIView *indicator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.height, self.frame.size.height)];
float delay = 0.4 * i;
[UIView animateWithDuration:1.2 delay:delay options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionRepeat animations:^{
} completion:^(BOOL finished) {
}];

[self addSubview:indicator];
[self.refreshIndicators addObject:indicator];
}

最佳答案

当您使用 for 循环(for (id _obj in object))枚举某些对象(例如 NSMutableArray 或 NSMutableSet)并在该循环中删除或添加某些对象到同一对象时,就会出现问题。这是不可能的并且会导致异常。

试试这个:将您的代码保持在下面的循环中。

@synchronized(self)
{
// your code goes here
}

希望这有帮助。

关于ios - 应用程序崩溃并出现异常 : *** Collection was mutated while being enumerated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34984796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com