xcode Ios 模拟器在尝试加载故事板时让我黑屏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13082749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:56:42  来源:igfitidea点击:

Ios simulator giving me a black screen when trying to load storyboard?

iosxcode

提问by J Shapiro

I have been trying to solve this problem for over 14 hours now...I am really hoping that someone could please help me load my storyboard. Everytime I try it non-programmatically, it decides it wants to keep it as a black screen (and its not the loading screen. I checked to see if it was in the initial view controller. Yet nothing. So I figure, maybe I need to do it programmatically. I've synthesized them properly as you can see. Still nothing. What am I doing wrong (there is no xcode error output).

我已经尝试解决这个问题超过 14 个小时了......我真的希望有人能帮我加载我的故事板。每次我以非编程方式尝试时,它都会决定将其保留为黑屏(而不是加载屏幕。我检查了它是否在初始视图控制器中。但什么都没有。所以我想,也许我需要以编程方式进行。正如你所看到的,我已经正确地合成了它们。仍然什么都没有。我做错了什么(没有 xcode 错误输出)。

Appdelegate.h

Appdelegate.h

#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
        UIWindow *window;
    UIViewController *viewController;
}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;
@end

AppDelegate.m

AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h"


@implementation AppDelegate

@synthesize window;
@synthesize viewController=_viewController;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc]
                   initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application {
    // Save data if appropriate
}

回答by J Shapiro

If you are using a Storyboard, you should remove the code you have written in the app delegate method; change it to look like this:

如果您使用的是 Storyboard,您应该删除您在应用程序委托方法中编写的代码;将其更改为如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

Next look at your build target properties (in your project navigator, click on the name of your project at the very top). Is your storyboard selected in the "Main Storyboard" section of the "Summary" pane?

接下来查看您的构建目标属性(在您的项目导航器中,单击最顶部的项目名称)。是否在“摘要”窗格的“主故事板”部分选择了您的故事板?

Finally go to the storyboard and make sure your view controller is selected as the initial view controller. Select the view controller scene and verify that the "Initial Scene: Is Initial View Controller" box in the attributes inspector pane is checked.

最后转到故事板并确保您的视图控制器被选为初始视图控制器。选择视图控制器场景并验证是否选中了属性检查器窗格中的“初始场景:是初始视图控制器”框。

If all of these steps have been verified and you're still seeing a blank screen, it's possible that there is a bug in your view controller. Try dragging a brand new view controller to the storyboard, add a label, and set it as the initial view controller. If you are able to see that scene launch, there is a problem with your original view controller (rather than it being an issue with the launching of your storyboard).

如果所有这些步骤都经过验证,但您仍然看到一个空白屏幕,则可能是您的视图控制器中存在错误。尝试将一个全新的视图控制器拖到故事板中,添加一个标签,并将其设置为初始视图控制器。如果您能够看到该场景启动,则说明您的原始视图控制器存在问题(而不是故事板启动的问题)。

回答by Tomasz Zab?ocki

First of all your viewControllerproperty is just a nil, it's not initialized anywhere. With this self.window.rootViewController = viewController;you just pass nil to rootViewController.

首先你的viewController财产只是一个零,它没有在任何地方初始化。有了这个,self.window.rootViewController = viewController;你只需将 nil 传递给rootViewController.

In Interface Builder you should have arrow indicating your initial view controller - as seen on this pictureor in Attributes Inspector as seen here

在 Interface Builder 中,您应该有箭头指示您的初始视图控制器 - 如本图所示或在 Attributes Inspector 中所示,如此处所示

You may also read excellent tutorial on storyboards here

你也可以在这里阅读关于故事板的优秀教程