gpt4 book ai didi

ios - 在 IOS 中调用另一个屏幕时出现异常

转载 作者:行者123 更新时间:2023-12-01 17:49:03 25 4
gpt4 key购买 nike

我是IOS开发的新手。在 Main.storyoard ,我添加了一个新的viewcontroller ,将其分配给一个新类(“LoginViewController”)并提供一个 StoryboardID(“loginview”)。
然后我在默认的viewcontroller上添加了一个按钮并尝试使用以下代码调用新创建的 viewcontroller .

    NSString * storyboardName = @"Main.storyboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"loginview"];
[self presentViewController:vc animated:YES completion:nil];

在调试过程中,当我单击按钮显示另一个屏幕时,出现以下异常

2016-05-04 12:04:40.793 gcmexample[1418:30458] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main.storyboard' in bundle NSBundle (loaded)' * First throw call stack: ( 0 CoreFoundation 0x0000000101150e65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000100840deb objc_exception_throw + 48 2 UIKit
0x0000000101c21669 -[UIStoryboard name] + 0 3 gcmexample
0x000000010033f2d6 -[ViewController btnSignout:] + 86 4 UIKit
0x00000001014ff194 -[UIApplication sendAction:to:from:forEvent:] + 92 5 UIKit 0x000000010166e6fc -[UIControl sendAction:to:forEvent:] + 67 6 UIKit 0x000000010166e9c8 -[UIControl _sendActionsForEvents:withEvent:] + 311 7 UIKit 0x000000010166daf8 -[UIControl touchesEnded:withEvent:] + 601 8 UIKit 0x000000010156e49b -[UIWindow _sendTouchesForEvent:] + 835 9 UIKit 0x000000010156f1d0 -[UIWindow sendEvent:] + 865 10 UIKit
0x000000010151db66 -[UIApplication sendEvent:] + 263 11 UIKit
0x00000001014f7d97 _UIApplicationHandleEventQueue + 6844 12 CoreFoundation 0x000000010107ca31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
+ 17 13 CoreFoundation 0x000000010107295c __CFRunLoopDoSources0 + 556 14 CoreFoundation 0x0000000101071e13 __CFRunLoopRun + 867 15 CoreFoundation
0x0000000101071828 CFRunLoopRunSpecific + 488 16 GraphicsServices
0x000000010492bad2 GSEventRunModal + 161 17 UIKit
0x00000001014fd610 UIApplicationMain + 171 18 gcmexample
0x000000010033ffdf main + 111 19 libdyld.dylib
0x000000010388c92d start + 1 20 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException



有谁知道这里的错误是什么?请帮忙。

最佳答案

试试这个:-

NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"loginview"];
[self presentViewController:vc animated:YES completion:nil];

关于ios - 在 IOS 中调用另一个屏幕时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37021038/

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