美文网首页
xcode创建不从main.storyboard启动的项目

xcode创建不从main.storyboard启动的项目

作者: 陈盼同学 | 来源:发表于2023-08-04 22:45 被阅读0次

    1,删除Main.StroyBoard文件和SceneDelegate.h/.m文件


    WechatIMG1089.png

    2,在info.plist文件中移除Application Scene Manifest.


    WechatIMG1090.png
    3,删除TARGETS下info的Main storyboard file base name以及Application Scene Manifest
    WechatIMG1096.png

    4,在AppDelegate.h添加window属性

    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow * window;
    
    @end
    

    5,在AppDelegate.m添加window配置信息,示例如下

    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        UIViewController *vc =[[UIViewController alloc]init];
        vc.view.backgroundColor = [UIColor yellowColor];
        self.window.rootViewController = vc;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    @end
    

    同时删除AppDelegate.m的如下代码

    - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        **return** [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
    }
    
    - (**void**)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
        // 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.
    }
    

    话外

    此时模拟器运行项目打印台可能会提示Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)"),此种提示不影响项目,如果介意,可按如下配置,在TARGETS下info里如下添加Application Scene Manifest即可消除提示


    image.png

    相关文章

      网友评论

          本文标题:xcode创建不从main.storyboard启动的项目

          本文链接:https://www.haomeiwen.com/subject/bqbmpdtx.html