OC/Swift工程去除MainStoryBoard

本文介绍了如何在Objective-C和Swift项目中移除MainStoryboard。步骤包括删除Main.storyboard文件,更新Info.plist,以及修改AppDelegate文件以实现自定义启动流程。通过这些步骤,开发者可以实现不依赖MainStoryboard的项目初始化。
摘要由CSDN通过智能技术生成

OC/Swift工程去除MainStoryBoard

背景

iOS MainStoryBoard 在实际开发过程中,使用场景并不多,(做做demo除外),但删除它的次数也不多,给CV战士提供一套快捷入口

准备

  • Xcode工程

OC去除ManStoryBoard

1,删除Main.storyboard文件
2,工程-> TARGETS -> Info.plist中 删除Main storyboard file base name
3,工程AppDelegate.m改造

//
//  AppDelegate.m
//  JDTVideoPlayer
//
//  Created by yuezhimin on 07/15/2020.
//  Copyright (c) 2020 JDT. All rights reserved.
//

#import "AppDelegate.h"
// 引入主控制器
#import "ViewController.h"
@implementation AppDelegate

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

    // Override point for customization after application launch.

    ViewController *viewController = [[ViewController alloc] init];
    //如果不需要NavigationController时,直接 self.window.rootViewController = viewController; UITabBarController一样逻辑
    UINavigationController *nVC = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = nVC;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end

Swift去除ManStoryBoard

1,删除Main.storyboard文件
2,工程-> TARGETS -> Info.plist中 删除Main storyboard file base name
3,工程AppDelegate.swift改造

//
//  AppDelegate.swift
//  CreateAppTest
//
//  Created by yuezhimin on 2020/10/28.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        self.window = UIWindow(frame: UIScreen.main.bounds)
        let vc = ViewController()
        let navVC = UINavigationController(rootViewController: vc)
        
        self.window?.rootViewController = navVC
        self.window?.backgroundColor = .white
        self.window?.makeKeyAndVisible()
        
        return true
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

☆MOON

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值