2010-12-02 7 views
0

Je suis l'expérience d'un plantage occasionnel de mon application iPhone où je reçois l'exception suivanteEnumeration Mutation Pendant UIView transitionWithView

NSGenericException', reason: '*** Collection <CALayerArray: 0x26f6b0> was mutated while being enumerated. 

Avec la trace de la pile sur le fil de plantage de

Thread 0 Crashed: 
0 libSystem.B.dylib     0x00078ac8 __kill + 8 
1 libSystem.B.dylib     0x00078ab8 kill + 4 
2 libSystem.B.dylib     0x00078aaa raise + 10 
3 libSystem.B.dylib     0x0008d03a abort + 50 
4 libstdc++.6.dylib     0x00044a20 __gnu_cxx::__verbose_terminate_handler() + 376 
5 libobjc.A.dylib      0x00005958 _objc_terminate + 104 
6 libstdc++.6.dylib     0x00042df2 __cxxabiv1::__terminate(void (*)()) + 46 
7 libstdc++.6.dylib     0x00042e46 std::terminate() + 10 
8 libstdc++.6.dylib     0x00042f16 __cxa_throw + 78 
9 libobjc.A.dylib      0x00004838 objc_exception_throw + 64 
10 CoreFoundation      0x0009f850 __NSFastEnumerationMutationHandler + 208 
11 libobjc.A.dylib      0x0000a51a objc_enumerationMutation + 18 
12 UIKit        0x00007bfe -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 142 
13 UIKit        0x00007c2e -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190 
14 UIKit        0x00007cd2 -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:] + 22 
15 UIKit        0x00007628 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 304 
16 UIKit        0x000074e8 -[UIView(Hierarchy) addSubview:] + 16 
17 UIKit        0x0006c350 +[UIViewControllerWrapperView wrapperViewForView:frame:] + 232 
18 UIKit        0x00077d0c -[UINavigationController _startTransition:fromViewController:toViewController:] + 468 
19 UIKit        0x00077abc -[UINavigationController _startDeferredTransitionIfNeeded] + 176 
20 UIKit        0x00077a00 -[UINavigationController viewWillLayoutSubviews] + 8 
21 UIKit        0x0006dca8 -[UILayoutContainerView layoutSubviews] + 132 
22 UIKit        0x0000fbc0 -[UIView(CALayerDelegate) _layoutSublayersOfLayer:] + 20 
23 CoreFoundation      0x0003e2e4 -[NSObject(NSObject) performSelector:withObject:] + 16 
24 QuartzCore       0x0000f942 -[CALayer layoutSublayers] + 114 
25 QuartzCore       0x0000f6fa CALayerLayoutIfNeeded + 178 
26 QuartzCore       0x000094c4 CA::Context::commit_transaction(CA::Transaction*) + 204 
27 QuartzCore       0x000092da CA::Transaction::commit() + 186 
28 QuartzCore       0x0002d9b6 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 46 
29 CoreFoundation      0x00030236 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10 
30 CoreFoundation      0x000300aa __CFRunLoopDoObservers + 406 
31 CoreFoundation      0x000276b4 __CFRunLoopRun + 848 
32 CoreFoundation      0x00027270 CFRunLoopRunSpecific + 224 
33 CoreFoundation      0x00027178 CFRunLoopRunInMode + 52 
34 GraphicsServices     0x000045ec GSEventRunModal + 108 
35 GraphicsServices     0x00004698 GSEventRun + 56 
36 UIKit        0x0000411c -[UIApplication _run] + 396 
37 UIKit        0x00002128 UIApplicationMain + 664 
38 iDriveGreen       0x00003026 main (main.m:13) 
39 iDriveGreen       0x00002ff0 start + 32 

Ce plantage est déclenché après l'exécution du code suivant.

StopRouteViewController *stopVC = [[StopRouteViewController alloc] init]; 
[UIView transitionWithView:self.navigationController.view 
        duration:0.5 
        options:UIViewAnimationOptionTransitionFlipFromLeft 
       animations:^{ 
        [self.navigationController pushViewController:stopVC animated:NO]; 
       } 
       completion:NULL]; 
[stopVC release]; 

Cela ressemble-t-il de manière flagrante à qui que ce soit? Ma pensée actuelle est que soit est lié à stopVC être libéré avant qu'il soit poussé ou avec la transition avec navigationController.view tout en poussant un nouveau viewController à la navigationController. Comme cela ne se produit qu'occasionnellement, j'aimerais avoir un peu plus de confiance avant de commettre un correctif potentiel.

+0

Qu'essayez-vous de faire ici? Essayez-vous de fournir vos propres animations personnalisées (faites pivoter vers la gauche et la droite) au lieu des animations Push et Pop par défaut de UINavigationController? –

+0

C'est correct Raj – matheeeny

Répondre

1

Oui, il s'agit d'une utilisation incorrecte de l'API. - [UINavigationController pushViewController: animé:] gère l'animation par lui-même. Même si vous passez NO comme deuxième argument, il manipule toujours la hiérarchie de vues, ce qui cause votre crash.

Fondamentalement, il n'y a aucune raison de mettre un appel à - [UINavigationController pushViewController: animated:] dans un bloc d'animation, comme vous l'avez fait. Si vous voulez animer la poussée de votre contrôleur, passez YES comme deuxième argument.

+0

J'essaye d'effectuer une animation personnalisée pendant l'appel pushViewController. Sinon, je ferais comme vous l'avez dit et j'appellerai seulement pushViewController et j'en aurai fini avec. – matheeeny

+0

Les animations push et pop personnalisées ne sont pas prises en charge par UINavigationController. Vous pouvez explorer et pousser dans UINavigationController sans animation, et manipuler les vues directement dans votre code pour obtenir l'effet visuel désiré, ou sous-classer UINavigationController pour remplacer les méthodes push et pop (probablement difficile et plein de dangers), ou écrire vos propres classe de contrôleur de navigation personnalisée (aussi difficile). – Ryan