gpt4 book ai didi

iphone - 崩溃呈现模态视图 Controller

转载 作者:行者123 更新时间:2023-12-03 20:16:21 26 4
gpt4 key购买 nike

我遇到了这个崩溃。它与其他线程类似,但又不一样。我想首先向用户显示一个模态视图 Controller ,然后转到特定的 View Controller 。按照提示,我在 - (void) viewDidAppear:(BOOL)animated 上执行此操作,并按照我所建议的方式应用延迟。

 - (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

如您所见,我等待 View 出现。这可能是操作系统错误吗?看起来它试图递归地呈现其他模态视图 Controller ,从而引发崩溃。非常感谢。

最佳答案

除了我在评论中挑剔之外,我想我也可以帮助解决这个问题。我认为你需要在其他地方寻找罪魁祸首。我使用以下代码段创建了一个新项目和一个 View Controller :

#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

按下导航 Controller 后,它可以完美地工作。它在黑白 View 之间递归交替,并在 sim 和 3G 设备上进行了测试。

也许由于某些通知或其他异步方式,您正在执行其他一些 View 转换?无论哪种方式,您都需要共享更多代码,以便任何人都知道问题出在哪里。

关于iphone - 崩溃呈现模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4897076/

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