IOS开发日志-ios新建项目后-将storyboard去掉,版本调整为IOS13以下

news/2025/2/5 10:40:01 标签: ios, cocoa, macos

目标IOS版本12,Xcode 16.2,记录ios新建项目后,如何将故事板storyboard和SceneDelegate 文件去掉,调整为代码开发。

在这里插入图片描述
创建后的项目中包含SceneDelegate,SceneDelegate 是 iOS 13 引入的类,用于管理应用程序的生命周期和界面显示。如果开发IOS13以下的项目,需要对SceneDelegate 进行调整。
在这里插入图片描述

调整步骤:

将 var window: UIWindow? 复制或者移动到 AppDelegate 当中。
在这里插入图片描述

删除 SceneDelegate
在这里插入图片描述

删除AppDelegate 中标红的代码。
在这里插入图片描述

删除 Main.storyboard 。

在这里插入图片描述

删除 Info.plist 中的标红部分。

在这里插入图片描述

设置默认显示的界面

AppDelegate 中添加如下代码。

        // 设置默认显示页面(此处为固定的写法)
        let controller = ViewController()
        self.window = UIWindow(frame: UIScreen.main.bounds)
        window!.rootViewController = controller
        window!.makeKeyAndVisible()

程序运行后,没有显示红色背景,并且出现了报错,说明没有加载到 ViewController ,检查一下。

Thread 1: “Could not find a storyboard named ‘Main’ in bundle NSBundle </Users/dengming/Library/Developer/CoreSimulator/Devices/E911900E-95D7-40F2-BDA0-F7EDCF15F82E/data/Containers/Bundle/Application/D17467AA-3EA9-4577-8B0B-9C16FC6941D9/cmMusic.app> (loaded)”

在这里插入图片描述

将target中info 中的 Main storyboard file base name 属性值,设置为空。

在这里插入图片描述

再次运行,已经可以成功加载到 ViewController ,并移除了故事板。

实现效果

在这里插入图片描述

附:AppDelegate 和 ViewController 代码

//
//  ViewController.swift
//  cmMusic
//
//  Created by deng ming on 2025/2/4.
//
import UIKit
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .red     
       // self.view.backgroundColor = .red
    }
}
//
//  ViewController.swift
//  cmMusic
//
//  Created by deng ming on 2025/2/4.
//
import UIKit
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .red
       // self.view.backgroundColor = .red
    }
}

http://www.niftyadmin.cn/n/5842157.html

相关文章

一表总结 Java 的3种设计模式与6大设计原则

设计模式通常分为三大类&#xff1a;创建型、结构型和行为型。 创建型模式&#xff1a;主要用于解决对象创建问题结构型模式&#xff1a;主要用于解决对象组合问题行为型模式&#xff1a;主要用于解决对象之间的交互问题 创建型模式 创建型模式关注于对象的创建机制&#xf…

优选算法合集————双指针(专题二)

好久都没给大家带来算法专题啦&#xff0c;今天给大家带来滑动窗口专题的训练 题目一&#xff1a;长度最小的子数组 题目描述&#xff1a; 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl1, …

DeepSeek本地部署的一些使用体会

春节期间我也尝试了一下Deepseek的本地部署&#xff0c;方案选用了Ollama Chatbox或AnythingLLM。Chatbox里有很多有意思的“助手”&#xff0c;而AnythingLLM支持本地知识库。 网上教程很多&#xff0c;总的来说还是很方便的&#xff0c;不需要费太多脑子。甚至可以这么说&a…

【C++】P1957 口算练习题

博客主页&#xff1a; [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: C 文章目录 &#x1f4af;前言&#x1f4af;题目描述输入格式&#xff1a;输出格式&#xff1a; &#x1f4af;我的做法代码实现&#xff1a; &#x1f4af;老师的做法代码实现&#xff1a; &#x1f4af;对比分析&am…

堆的实现——对的应用(堆排序)

文章目录 1.堆的实现2.堆的应用--堆排序 大家在学堆的时候&#xff0c;需要有二叉树的基础知识&#xff0c;大家可以看我的二叉树文章&#xff1a;二叉树 1.堆的实现 如果有⼀个关键码的集合 K {k0 , k1 , k2 , …&#xff0c;kn−1 } &#xff0c;把它的所有元素按完全⼆叉树…

PAT甲级1052、Linked LIst Sorting

题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are supposed to sort the stru…

为AI聊天工具添加一个知识系统 之76 详细设计之17 正则表达式 之4 正则表达式模板

本文要点 要点 1、三“化” 使用三种不同的定义方法&#xff1a; 规定定义法 -线性回归/内涵定义法--一阶迭代/外延定义法--单调递归 整体形成 一个双人零和 的局面 <Class()外延式, Type()内涵式> Method()规定式。给出 问题“law 是什么”的三种答案&#xff1a; …

Sumatra PDF:小巧免费,满足多样阅读需求

Sumatra PDF是一款完全免费的本地阅读器软件&#xff0c;以小巧的体积和全面的功能受到用户青睐。如今&#xff0c;它已经更新到3.3版本&#xff0c;带来了更多实用功能&#xff0c;尤其是新增的注释功能&#xff0c;值得我们再次关注。 软件特色 轻量级体积&#xff1a;压缩…