gpt4 book ai didi

ios 准备 segue 导致崩溃

转载 作者:行者123 更新时间:2023-11-28 21:44:10 30 4
gpt4 key购买 nike

我是 ios 开发的新手,在我尝试做的事情上遇到了障碍。

我的方法中有这段代码,旨在将特定的 NSObject 从这个 View 传递到下一个 View ,但是它总是让我的应用程序崩溃。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showPDF"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
PDFViewController *controller = (PDFViewController *)navController.topViewController;
controller.yourName = self.yourName;
}

我已经调试通过并确定它是导致它崩溃的第四行。

输出:

2015-06-19 11:47:00.955 iOSPDFRenderer[2455:70005] -[PDFViewController topViewController]: unrecognized selector sent to instance 0x7c5375d0
2015-06-19 11:47:00.959 iOSPDFRenderer[2455:70005] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PDFViewController topViewController]: unrecognized selector sent to instance 0x7c5375d0'
*** First throw call stack:
(
0 CoreFoundation 0x01f2b466 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01bb4a97 objc_exception_throw + 44
2 CoreFoundation 0x01f332c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x01e7bbc7 ___forwarding___ + 1047
4 CoreFoundation 0x01e7b78e _CF_forwarding_prep_0 + 14
5 iOSPDFRenderer 0x000ed00e -[ViewController prepareForSegue:sender:] + 238
6 UIKit 0x00985d77 -[UIStoryboardSegueTemplate _perform:] + 199
7 UIKit 0x00985e05 -[UIStoryboardSegueTemplate perform:] + 116
8 libobjc.A.dylib 0x01bca7cd -[NSObject performSelector:withObject:withObject:] + 84
9 UIKit 0x00368340 -[UIApplication sendAction:to:from:forEvent:] + 99
10 UIKit 0x003682d2 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
11 UIKit 0x0049ca56 -[UIControl sendAction:to:forEvent:] + 69
12 UIKit 0x0049ce73 -[UIControl _sendActionsForEvents:withEvent:] + 598
13 UIKit 0x0049c0dd -[UIControl touchesEnded:withEvent:] + 660
14 UIKit 0x003b8ffa -[UIWindow _sendTouchesForEvent:] + 874
15 UIKit 0x003b9ad5 -[UIWindow sendEvent:] + 791
16 UIKit 0x0037ebb1 -[UIApplication sendEvent:] + 242
17 UIKit 0x0038ebf6 _UIApplicationHandleEventFromQueueEvent + 21066
18 UIKit 0x00362bc7 _UIApplicationHandleEventQueue + 2300
19 CoreFoundation 0x01e4e98f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20 CoreFoundation 0x01e4449d __CFRunLoopDoSources0 + 253
21 CoreFoundation 0x01e439f8 __CFRunLoopRun + 952
22 CoreFoundation 0x01e4337b CFRunLoopRunSpecific + 443
23 CoreFoundation 0x01e431ab CFRunLoopRunInMode + 123
24 GraphicsServices 0x022da2c1 GSEventRunModal + 192
25 GraphicsServices 0x022da0fe GSEventRun + 104
26 UIKit 0x003669b6 UIApplicationMain + 1526
27 iOSPDFRenderer 0x000ec94d main + 141
28 libdyld.dylib 0x02e58ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

有人知道为什么会这样吗?

非常感谢!

最佳答案

根据您的错误日志和代码,我认为您的顶部没有导航 Controller 。尝试以下操作:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showPDF"]){
PDFViewController *controller = (PDFViewController *))segue.destinationViewController;
controller.yourName = self.yourName;
}
}

关于ios 准备 segue 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936338/

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