Swift 为什么我的Xcode模拟器只是给我显示一个黑屏?没有场景代理集?
我以前也见过类似的问题,但这篇帖子很老,没有一个答案对我有用。我正在为cs50的移动轨迹编写一个非常简单的代码,它只是一个小小的pokedex,但每当我运行我的应用程序模拟器时,我都会遇到一个黑屏而不是应用程序 下面是它在调试器中的说明(如果有帮助):Swift 为什么我的Xcode模拟器只是给我显示一个黑屏?没有场景代理集?,swift,xcode,ios-simulator,Swift,Xcode,Ios Simulator,我以前也见过类似的问题,但这篇帖子很老,没有一个答案对我有用。我正在为cs50的移动轨迹编写一个非常简单的代码,它只是一个小小的pokedex,但每当我运行我的应用程序模拟器时,我都会遇到一个黑屏而不是应用程序 下面是它在调试器中的说明(如果有帮助):没有场景委托集。必须指定场景代理类才能使用主情节提要文件。 AppDelegate: import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDel
没有场景委托集。必须指定场景代理类才能使用主情节提要文件。
AppDelegate:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
信息:
CfBundledDevelopmentRegion
$(开发语言)
Cbundlexecutable
$(可执行文件名称)
CbundleIdentifier
$(产品\捆绑包\标识符)
CbundleInfo字典版本
6
CFBundleName
$(产品名称)
CbundlePackageType
$(产品\捆绑\包装\类型)
CbundleShortVersionString
1
循环流化床锅炉
1.
LSREQUIRESPHONEOS
UIApplicationSceneManifest
UIApplicationSupportsMultipleScenes
UISCeneConfiguration
UIWindowsCensessionRole应用程序
UISCeneConfiguration名称
默认配置
UISCenedLegateClassName
$(产品\u模块\u名称).SceneDelegate
UISCenestryBoardFile
主要
UILaunchStoryboardName
发射屏
UIMainstryBoardFile
主要
UIRequiredDeviceCapabilities
armv7
UI支持接口方向
UIInterfaceOrientationPortrait
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight
UI支持界面方向~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientation上下方向图
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight
这是您项目名称中的。不要那样做
请记住,项目名称不是面向用户的。你可以用一个包含é
的名字来调用这个应用程序,但不要试图用这样的名字来启动一个项目。糟糕的事情会发生(你只是遇到了其中一个)
我建议你从头开始。这将比尝试重命名项目及其所有相关内容更容易。这是项目名称中的。不要那样做
请记住,项目名称不是面向用户的。你可以用一个包含é
的名字来调用这个应用程序,但不要试图用这样的名字来启动一个项目。糟糕的事情会发生(你只是遇到了其中一个)
我建议你从头开始。这将比尝试重命名项目及其所有相关内容更容易。您使用的是故事板吗?ViewController
是否设置为初始视图控制器?如果这些看起来没问题,请尝试使用Xcode的视图调试器来找出它认为屏幕上显示的内容。@PhillipMills我将它给我的消息添加到了我的原始帖子中。如果你能帮助我理解这一点,并告诉我它希望我做什么,那就太好了。你给我们展示了错误的代码。我们需要看到的是应用程序代理、场景代理和Info.plist。还有main.swift,如果有。@matt我添加了应用程序和场景代理。我是Xcode和swift的新手,所以我不确定如何正确地共享info.plist,但我将其添加为源代码。没有主管道。swift@matt我现在把我能做的都加进去了。很抱歉你在用故事板吗?ViewController
是否设置为初始视图控制器?如果这些看起来没问题,请尝试使用Xcode的视图调试器来找出它认为屏幕上显示的内容。@PhillipMills我将它给我的消息添加到了我的原始帖子中。如果你能帮助我理解这一点,并告诉我它希望我做什么,那就太好了。你给我们展示了错误的代码。我们需要看到的是应用程序代理、场景代理和Info.plist。还有main.swift,如果有。@matt我添加了应用程序和场景代理。我是Xcode和swift的新手,所以我不确定如何正确地共享info.plist,但我将其添加为源代码。没有主管道。swift@matt我现在把我能做的都加进去了。很抱歉
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>