09 2023 档案
摘要:回调函数: 回调函数是一种将函数作为参数传递给另一函数的策略。当特定事件或条件发生时,传递的函数(即回调函数)将被调用。这种机制允许在事件发生时执行自定义的代码,因此它是异步编程的重要组成部分。在Swift中,可以使用闭包(closure)或函数作为回调函数。 假设你有一个函数叫做greet(),它
阅读全文
摘要:let g = F(a: s ?? 0.0, b: l ?? 0.0, c: d ?? 0.0) 这段代码在创建一个名为g的F对象。F是一个自定义类,它的实例化对象包含一些目标值,如a、b和c。这些目标值通过可选链操作符(??)设置,如果对应的变量为空(nil),那么就会使用默认值0.0。 ?? 是
阅读全文
摘要:alertWithTitle(title: "输入信息", message: "请输入您的姓名:", placeHolders: [], buttons: ["确定"], defaultButtonIndex: 0, cancelButtonIndex: 0, defaultText: "张三");
阅读全文
摘要:navigationController?.pushViewController(fileOperation, animated: true) 通过导航控制器(navigationController)将一个新的视图控制器(fileOperation)推入栈顶,同时以动画的形式展示这个过程。如果na
阅读全文
摘要:tableView.deselectRow(at: indexPath, animated: true) 作用:在表视图(UITableView)中取消选中某一行。 在表格视图中,用户可以点击或轻击一行来选中它。如果你想要在程序中取消选中这一行,就可以使用deselectRow(at:indexPa
阅读全文
iOS开发Swift-UITableView-func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
摘要:func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print(indexPath.row) } 作用:当选中此cell时需要执行的方法. 用于响应UITableView中某一行的选中事件。
阅读全文
摘要:as 是强制类型转换运算符。使用它可以将一个对象的类型转换为另一种类型。如果类型转换失败,会触发一个运行时错误。as! 是强制类型转换运算符。使用它可以将一个对象的类型转换为另一种类型。如果类型转换失败,会触发一个运行时错误。它与 as 类似,但是它更加强烈地说明了类型转换是成功的。as? 是可选类
阅读全文
摘要:tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath) 作用:复用cell.可以用标识符从表视图中获得可重用单元格.for: indexPath通过指定单元格位置获得可重用单元格,不需要判断. 用于 dequeue(
阅读全文
摘要:func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cellid = "testCellID" //cell的ID var cell = tableV
阅读全文
摘要:func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 6 } 返回一个整形. 作用: UITableView的DataSource,用来确定cell的个数.number
阅读全文
摘要:1.新建一个LittlePink项目 完成一些配置. 2.在Main中新增一个Tab Bar Controller. 把箭头给TbaBar Controller. 除了原有的一个ViewController外,再拉两个ViewController,使Main中共有5个ViewController.
阅读全文
摘要:1.新建项目 2.添加Git仓库 添加自己的gitHub账号. 3.Token获取方式: Settings. Developer Settings. 获取个人Token. 填写相关内容. 得到Token后复制它,拿到Xcode中登录. 填写相关信息. 创建后打开GitHub,查看自己的所有仓库,发现
阅读全文
摘要:AppDelegate: import UIKit import CoreData //包含App的部分生命周期函数(钩子函数),也有其余函数(如推送) @main class AppDelegate: UIResponder, UIApplicationDelegate { func applic
阅读全文
摘要:1.在待办事项App中,寻找沙盒路径. TodosTableVC-Delegate: import UIKit //UITableViewDelegate extension TodosTableVC{ //当用户点击cell的时候调用 override func tableView(_ table
阅读全文
摘要:1.点击某一条待办事项,出现编辑界面,可对待办事项的文本进行修改. 不重新设计界面,而是将新增页面进行修改复用. 2.为新增页面取Storyboard ID为TodoTableViewControllerID. 3.为列表最右边加一个小箭头.选中TodoCellID,将属性中的Selection修改
阅读全文
摘要:反向传值是指将后续页面(2)得到的值传回首页(1). 1.在2页面代码中写protocol. protocol TodoTableViewControllerDelegate{ func didAdd(name: String) func didEdit(name: String) } 制定了一个名
阅读全文
摘要:1.制作新增界面UI 进入Main界面,选中当前页面,点击右下角,选择Navigation Controller.Navigation Controller是一个容器,用于控制页面跳转. 新建一个Table View Controller,作为跳转之后的页面. 选中Table View,将他的Con
阅读全文
摘要:1.创建新项目 为项目添加图标 2.将Table View Controller添加到界面中 将箭头移动到Table View上来,代表它是首页(根页面).选中ViewController,点击Delete,对它进行删除.将代码ViewController.swift也删除掉. 新建一个Cocoa
阅读全文
摘要:1.创建次页的controller class 在Main中选择次界面,点击左上方黄色的圈圈,将它的Custom Class中的class修改为QueryViewController. 将QueryViewController中自动生成的首页传值方法复制到ViewController中去.去掉注释符
阅读全文
摘要:1.Int或Double转字符串 let x = 20 let y = "\(x)" let z = String(x) 2.Double转Int(去掉小数点后面的) Int(1.9) 3.Int转Double Double(1) 4.向上转型 class A{ //A父类 } class B: A
阅读全文
摘要:1.获取用户当前所在的位置 在infi中点击加号,选择权限:当用户使用app的时候获取位置权限. 填写使用位置权限的目的. 2.获取用户的经纬度. ViewController: import UIKit import CoreLocation class ViewController: UIVie
阅读全文
摘要:问题描述: 引入了一个新的cocoapods依赖之后,启动运行,显示Fail,报错File not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/li
阅读全文
摘要:1.进入Android Studio官网 https://developer.android.google.cn/studio 2.点击下载Android Studio. 3.将说明拉到最下方,选择Mac With Apple Chip.苹果芯片选择Apple Chip,如果是Intel芯片可以选择
阅读全文
摘要:终端代理命令: 小飞机:export https_proxy=http://127.0.0.1:1087 回车export http_proxy=http://127.0.0.1:1087 回车 Clash:export https_proxy=http://127.0.0.1:7890 回车exp
阅读全文
摘要:问题描述: 在终端命令行安装cocoapods时,可能出现如下问题: Error installing cocoapods: The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1
阅读全文
摘要:问题描述: 通过Homebrew安装cocoapods时,输入命令行 brew install cocoapods 出现如下报错: zsh: command not found: brew zsh:找不到命令:brew 问题解决: 使用以下命令,重新安装Homebrew. /bin/zsh -c "
阅读全文
摘要:问题描述: iOS开发时,当使用用户的位置权限时,获取用户经纬度报错:Error Domain=kCLErrorDomain Code=1 "(null)",错误域=kCLError域代码=1“(null)” 解决方法: 打开模拟机的设置-通用-语言与地区 将地区设置为中国(如果你的开发位置在中国的
阅读全文
摘要:1.创建项目 2.设置好测试机型,App显示名称,以及关闭横向展示. 3.下载SF Symbols. https://developer.apple.com/sf-symbols/ 右上角搜索 search ,可以找到很多系统自带图标.选择喜欢的图标,拷贝图标的名字. 插入一个Button,在Ima
阅读全文
摘要:1.类的继承 class Animal { func breathe(){ //... } } class Cat: Animal{ var hasHair = true } let cat = Cat() cat.breathe() cat.hasHai class SmallCat: Cat{
阅读全文
摘要:1.根据用户回答计算得分 ViewController.swift: import UIKit class ViewController: UIViewController { var questionIndex = 0 var score = 0 @IBOutlet weak var questi
阅读全文