xcode創建不從main.storyboard啟動的項目

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
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容