2011-02-04 5 views
3

충돌이 있습니다. 다른 스레드와 비슷하지만 같지 않습니다. 먼저 사용자가 특정보기 컨트롤러로 이동하는 모달보기 컨트롤러를 보여주고 싶습니다. 힌트 다음에, 나는 그것을한다. - (무효) viewDidAppear : (BOOL) 애니메이션을 적용하고 추천 된대로 지연을 적용한다.충돌이있는 모달 뷰 컨트롤러

- (void) viewDidAppear:(BOOL)animated 
    { 
     [super viewDidAppear:animated]; 
     [self performSelector:@selector(presentMyModal) withObject:nil afterDelay:1]; 
    } 



    - (void) presentModal{ 
    ModalViewController *modal = [[[ModalViewController alloc] init] autorelease]; 
    [self presentModalViewController:modal animated:YES]; 
    } 

나중에, 람직하게 충돌합니다. 콘솔에서이 메시지를받습니다.

<Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-1447.6.4/UIWindowController.m:186 
Thu Feb 3 10:00:44 unknown MyApp[1830] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x454260> to <ModalViewController: 0x47af00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed' 
    *** Call stack at first throw: 
    (
     0 CoreFoundation      0x3759dc7b __exceptionPreprocess + 114 
     1 libobjc.A.dylib      0x32d9bee8 objc_exception_throw + 40 
     2 CoreFoundation      0x3759dac3 +[NSException raise:format:arguments:] + 70 
     3 Foundation       0x351a3e73 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62 
     4 UIKit        0x359e92a8 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 208 
     5 UIKit        0x359e8c98 -[UIViewController presentModalViewController:withTransition:] + 2792 
     6 UIKit        0x35a7b51c -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 116 
     7 UIKit        0x359e84c0 -[UIViewController presentModalViewController:withTransition:] + 784 
     8 UIKit        0x359e8060 -[UIViewController presentModalViewController:animated:] + 96 
     9 MyApp       0x0005d57f -[MyAppViewController presentMyModal] + 58 
     10 Foundation       0x351724db __NSFireDelayedPerform + 366 
     11 CoreFoundation      0x37552305 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 16 
     12 CoreFoundation      0x37551cd9 __CFRunLoopDoTimer + 988 
     13 CoreFoundation      0x37521a91 __CFRunLoopRun + 1184 
     14 CoreFoundation      0x3752150b CFRunLoopRunSpecific + 226 
     15 CoreFoundation      0x37521419 CFRunLoopRunInMode + 60 
     16 GraphicsServices     0x33e76d24 GSEventRunModal + 196 
     17 UIKit        0x3591d57c -[UIApplication _run] + 588 
     18 UIKit        0x3591a558 UIApplicationMain + 972 
     19 MyApp       0x0000e75f main + 50 
     20 MyApp       0x0000e6e8 start + 52 

볼 수 있듯이, 나는보기가 나타날 때까지 기다립니다. OS 버그일까요? 재귀 적으로 다른 모달보기 컨트롤러를 제시하려고 시도하는 것처럼 보이고, provoquing 충돌이 발생합니다. 고마워요.

+0

그냥 다른 뷰를 보여주는 대신에 바로 ModalViewController를 보여줄까요? – willcodejavaforfood

+0

답변 해 주셔서 감사합니다. 가급적이면, 우리는 약간의 견해를 보여주고 싶습니다. 그러나 우리는 그것을 고려할 것입니다. – toupper

+0

@selector (presentMyModal)에 오타가 있습니다 -이 함수는 presentModal입니다. 하지만 여기에 제시하기 전에 코드를 벗겨 냈을 것입니다. 그렇지 않으면 충돌 로그에서 결코 멀리 가지 않을 것입니다 .-) – Mayjak

답변

0

나는 코멘트에서 까다 롭지 않다는 점을 제외하고 나는 이것도 도와 줄 수 있다고 생각했다. 나는 범인을 다른 곳에서 찾아야한다고 생각합니다. 나는 새로운 프로젝트와이 미리보기와보기 컨트롤러 생성 :

#import "VC1.h" 


@implementation VC1 

- (void) viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [self performSelector:@selector(presentModal) withObject:nil afterDelay:1.0]; 
} 

- (void)presentModal { 
    static int colorChooser = 0; 
    VC1 *vc1 = [[[VC1 alloc] init] autorelease]; 
    switch (colorChooser%2) { 
    case 0: 
     vc1.view.backgroundColor = [UIColor whiteColor]; 
     break; 
    default: 
     vc1.view.backgroundColor = [UIColor blackColor]; 
     break; 
    } 
    colorChooser++; 
    [self presentModalViewController:vc1 animated:YES]; 
} 

@end 

을 그리고 네비게이션 컨트롤러에 밀어 후 완벽하게 작동합니다. 시뮬레이션과 3G 장치 모두에서 검정과 흰색보기를 재귀 적으로 번갈아 가면서 테스트합니다.

일부 알림 또는 다른 비동기적인 수단으로 인해 다른보기 전환을 수행하고있을 수 있습니까? 어느 쪽이든 누군가가 문제의 위치를 ​​알 수 있도록 코드를 더 많이 공유해야합니다.

+0

예, 다른 전환을 수행하고 있습니다. 모달보기 컨트롤러가 불만입니다. 그들은 둘 다 갈등을 겪을 것이라고 추측하지만 왜 모르는가? 모달 뷰를 제공하는 뷰 컨트롤러의 viewDidAppear이 호출 될 때 처음에는 완전히 해제되기를 바랍니다. – toupper

0

우리가 선호하는 해결책은 [UIViewController presentViewController : animated : completion :]을 사용하고 완료 블록에서 다음 작업 (예 : 다른 VC 제시)을 수행하는 것입니다. 예를 들어

:

[self presentViewController:yourViewController animated:YES completion:^{ 
    [yourViewController presentMyModal]; 
}]; 

이 방법은 아이폰 OS 5.0에 도입 하였다.