Xcode11.0更新之后,新建项目工程遇到的黑屏现象及解决办法

啰嗦几句:上周吧,我们Xcode更新到了11.0,有的人可能还没有发现,新建的项目中多了一个场景代理类目#import "SceneDelegate.h",至于怎么用的,我目前还没有定论。你们可以尝试一下,新建一个项目工程,在ViewController里面写一个按钮buton渲染界面,用真机调试一下,再用模拟器调试一下,手机调试会出现黑屏,模拟器呢,会出现button按钮,现在公司项目都是之前写好的,可能不会存在这样问题。下面就一一看下问题

第一、首先要保证你的xcode是最新的
Xcode11.0 2019-09-27 20.18.27.png

Xcode更新之后,少了很多的模拟器,当然这是可以自行添加的,并无大碍
屏幕快照 2019-09-27 20.21.37.png

项目创建完之后,项目中多了一个场景代理类目,至于怎么用的,鉴于刚发现,还再研究中
屏幕快照 2019-09-27 20.14.16.png

今天下午我新建一个工程想写一个波浪效果,发现了以上问题及以下问题,我把运行的截图发一下
自己的手机上调试的结果 2019-09-27 20.25.21.png

这是模拟器运行的效果,模拟器是没问题的
模拟器上运行的 2019-09-27 20.26.15.png

一、解决办法一(以失败告终)在AppDelegate引入

#import "AppDelegate.h"
#import "ViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
//   测试写一下 没有效果 我写的两个波浪没有了
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    ViewController *home = [[ViewController alloc] init];
    _navController = [[UINavigationController alloc] initWithRootViewController:home];
     [_navController.navigationBar setBackgroundColor:[UIColor blueColor]];
     [self.window setRootViewController:_navController];
//    self.window.rootViewController = home;
    [self.window makeKeyAndVisible];
    
//    添加这个运行之后会报错
    
    return YES;
}

这个方法第一件想到要加上的,可是不行,解决办法是不行的毕竟刚出啦,有没有相关的说明及解释
二、遇到的场景代理类目#import "SceneDelegate.h"

#import 

@interface SceneDelegate : UIResponder 

@property (strong, nonatomic) UIWindow * window;

@end
#import "SceneDelegate.h"

@interface SceneDelegate ()

@end

@implementation SceneDelegate


- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
//    使用此方法可选地配置并将UIWindow ' window '附加到提供的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).
//    这个委托并不意味着连接的场景或会话是新的(请参见“application:configurationForConnectingSceneSession”)。
}


- (void)sceneDidDisconnect:(UIScene *)scene {
    // 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).
//    场景稍后可能重新连接,因为它的会话没有必要被丢弃(请参见“application: diddiscardscenes”)。
}


- (void)sceneDidBecomeActive:(UIScene *)scene {
    // 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.
}


- (void)sceneWillResignActive:(UIScene *)scene {
    // 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).
}


- (void)sceneWillEnterForeground:(UIScene *)scene {
    // Called as the scene transitions from the background to the foreground.
    // Use this method to undo the changes made on entering the background.
}


- (void)sceneDidEnterBackground:(UIScene *)scene {
    // 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.
}

@end

昨天群里有人说可以在SceneDelegate添加WaterWaveView
我早上试了下,不行

#import "SceneDelegate.h"
#import "ViewController.h"
@interface SceneDelegate ()

@end

@implementation SceneDelegate


- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)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).
    
    
    //   测试写一下 没有效果 模拟器和真机全都黑屏
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        
        ViewController *home = [[ViewController alloc] init];
        _navController = [[UINavigationController alloc] initWithRootViewController:home];
         [_navController.navigationBar setBackgroundColor:[UIColor blueColor]];
         [self.window setRootViewController:_navController];
//        self.window.rootViewController = home;
        [self.window makeKeyAndVisible];

}

2019.9.29

今天又打了NSLog试了
NSLog(@"我走到这里了_____01") 2019-09-29 09.24.39.png

提示UINavigationController为nil,本来就没有设置

     NSLog(@"我走到这里了_____01");
     self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
     self.window.backgroundColor=[UIColor whiteColor];
     [self.window makeKeyAndVisible];
    ViewController *root=[[ViewController alloc]init];
     self.window.rootViewController=root;

我又试着把SceneDelegate.h.m两个文件删除依然没有用

解决办法:

#import 

@interface AppDelegate : UIResponder 

@property (strong, nonatomic) UIWindow * window; //添加即可解决

@end

SceneDelegate这个东西是管理window的,为了iPadOS的多进程准备的(可以同时开启多个相同App)

有道翻译了下,还是不会用,脑袋有瑕疵啊,哎,有大佬会用的可以评论里指点一二,拜谢!!!!!

本文代码地址:https://github.com/ZongAng123/TheWaves.git
本人微信:zaxm1993

你可能感兴趣的:(Xcode11.0更新之后,新建项目工程遇到的黑屏现象及解决办法)