我的代码片段如下。这会导致应用程序崩溃。奇怪的是,该应用程序仅在我创建档案并将档案加载到我的设备上时才会崩溃。如果我直接从 XCode 在设备上运行它,它运行良好。
for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 12; j++) {
        UILabel *label = (UILabel *)[self.view viewWithTag:((j+1) * 10 + (i+1))];
        [UIView animateWithDuration:1.0
                         animations:^{
                             label.alpha = 0.0f;
                             label.text = [cryptograms objectAtIndex:i * 12 + j];
                             label.alpha = 1.0f;
                         }];
    }
}
但是,如果我使用以下代码片段创建存档,则可以正常工作。
for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 12; j++) {
        UILabel *label = (UILabel *)[self.view viewWithTag:((j+1) * 10 + (i+1))];
        [label setText:[cryptograms objectAtIndex:i * 12 + j]];
    }
}
我已经验证问题不在于数组的大小。数组总是有 96 个元素。崩溃日志显示以下内容..
Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000017
Crashed Thread:  0
Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x37148584 _cache_getImp + 4
1   libobjc.A.dylib                 0x37148fa0 lookUpMethod + 24
2   libobjc.A.dylib                 0x3714a1e2 class_respondsToSelector + 26
3   CoreFoundation                  0x382c3638 ___forwarding___ + 372
4   CoreFoundation                  0x3821b204 _CF_forwarding_prep_0 + 20
5   GridSoftToken                   0x000990ae __41-[ViewController updateCryptogramLabels:]_block_invoke_0 (ViewController.m:69)
6   UIKit                           0x375bae80 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:animations:start:completion:] + 492
7   UIKit                           0x37672172 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:] + 54
8   GridSoftToken                   0x0009903c -[ViewController updateCryptogramLabels:] (ViewController.m:66)
9   GridSoftToken                   0x00098dc2 -[ViewController viewDidAppear:] (ViewController.m:44)
10  UIKit                           0x3760b2c8 -[UIViewController _setViewAppearState:isAnimating:] + 132
11  UIKit                           0x37627f24 -[UIViewController _executeAfterAppearanceBlock] + 48
关于如何解决此问题的任何想法?我显然可以摆脱动画,但我想保留它。