2011-02-04 63 views
3

我有這個崩潰。它與其他線程類似,但不一樣。 我想先顯示一個模式視圖控制器,用戶轉到特定的視圖控制器。按照提示,我在 - (void)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]; 
    } 

之後,ramdomly它崩潰。我在控制檯中收到此消息:

<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 

正如您所看到的,我一直等到查看出現。這可能是一個操作系統錯誤?它似乎試圖遞歸地呈現其他模式視圖控制器,導致崩潰。 非常感謝。

+0

不能直接顯示ModalViewController而不是先顯示其他視圖? – willcodejavaforfood 2011-02-04 10:49:33

+0

感謝您的回答。最好不要,我們想展示一下這個觀點。不過,我們會考慮到它。 – toupper 2011-02-04 11:06:58

回答

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

我們首選的解決方案是使用 - [UIViewController presentViewController:animated:completion:]並在完成塊中執行下一個動作(例如,呈現另一個VC)。

例如:

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

此方法在IOS 5.0中引入的。

相關問題