gpt4 book ai didi

ios - 运行我的第一个 iOS 应用程序时收到 SIGABRT

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

尝试使用 Xcode 5.1 编写我的第一个 iPhone 应用程序。这是我的 AppDelegate 代码的一部分

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddViewController"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];

return YES;
}

我有一个名为“Main.Storyboard”的 Storyboard,带有Navigation ControllerView Controller

当我运行我的应用程序时,我收到 SIGABRT 错误和 NSInternalInconsistencyException 异常

谁能帮我解决这个错误?

谢谢。

最佳答案

为什么要将 subview 添加为 UINavigationController.view 并将 Root View 添加为 view-controller?您的代码必须如下所示:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddViewController"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.navigationController];

[self.window makeKeyAndVisible];

return YES;
}

并验证您的 View Controller 的标识符设置是否正确,您在上面给出。

关于ios - 运行我的第一个 iOS 应用程序时收到 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23109612/

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