当前位置:网站首页>Apple 已弃用 NavigationView,使用 NavigationStack 和 NavigationSplitView 实现 SwiftUI 导航
Apple 已弃用 NavigationView,使用 NavigationStack 和 NavigationSplitView 实现 SwiftUI 导航
2022-07-05 15:47:00 【知识大胖】
Apple 已弃用 NavigationView,它以前被用作封装视图堆栈,这些视图本质上是在呈现时推送并在关闭时弹出的视图。这是 iOS 导航从一开始就使用的熟悉方式,没有物理后退按钮,但顶部有一个导航栏,有一个后退按钮,描述了“后退”的位置。
有两种实现导航的新方法,但它们最终在 iPhone 上看起来非常相似,原因我将在后面讨论。
让我们开始吧!
NavigationStack
这个应用程序非常简单地从几个Hashable和Identifiable结构开始。
Screen存储导航状态的枚举必须是Hashable,因为新的初始化程序需要NavigationLink它,我稍后将使用它。为了成为Hashable相关的值也需要是Hashable。如果它们只是 String和 an ,这仍然是正确的Int,但我想利用ForEachwhich 要求类型也是Identifiable。作为原始值类型String并且Int是可互换的,并且它们没有定义它们的唯一属性。
我已将数据添加ContentView为两个数组。
我可以(并且可能应该)使用 anObservableObject来存储数据,但我宁愿编写更多代码来专门演示导航。
import Foundation
struct Word: Hashable, Identifiable {
let id = UUID()
let name: String
}
struct Number: Hashable, Identifiable {
let id = UUID()
let value: Int
}
enum Screen: Hashable {
case word(Word)
case number(Number)
边栏推荐
- Dataarts studio data architecture - Introduction to data standards
- ES6深入—ES6 Class 类
- 对象和类的关系
- Cartoon: what is MapReduce?
- abstract关键字和哪些关键字会发生冲突呢
- Five common negotiation strategies of consulting companies and how to safeguard their own interests
- obj解析为集合
- 一文带你吃透js处理树状结构数据的增删改查
- 20.[STM32]利用超声波模块和舵机实现智能垃圾桶功能
- 16.[STM32]从原理开始带你了解DS18B20温度传感器-四位数码管显示温度
猜你喜欢
Research and practice of super-resolution technology in the field of real-time audio and video
Six common transaction solutions, you sing, I come on stage (no best, only better)
The OBD deployment mode of oceanbase Community Edition is installed locally
vlunhub- BoredHackerBlog Social Network
16. [stm32] starting from the principle, I will show you the DS18B20 temperature sensor - four digit digital tube displays the temperature
SQL injection sqllabs (basic challenges) 11-20
Convert obj set to entity set
Parameter type setting error during batch update in project SQL
ES6深入—ES6 Generator 函数
我们为什么要学习数学建模?
随机推荐
记一次'非常诡异'的云安全组规则问题排查过程
17. [stm32] use only three wires to drive LCD1602 LCD
Mistakes made when writing unit tests
数据湖(十四):Spark与Iceberg整合查询操作
践行自主可控3.0,真正开创中国人自己的开源事业
Cartoon: what is distributed transaction?
Today's sleep quality record 79 points
五种常见的咨询公司谈判策略以及如何维护自己的利益
Use of set tag in SQL
Clock switching with multiple relationship
项目中批量update
obj解析为集合
Example project: simple hexapod Walker
项目sql中批量update的时候参数类型设置错误
Single merchant v4.4 has the same original intention and strength!
写单元测试的时候犯的错
16. [stm32] starting from the principle, I will show you the DS18B20 temperature sensor - four digit digital tube displays the temperature
19.[STM32]HC_SR04超声波测距_定时器方式(OLED显示)
Practice independent and controllable 3.0 and truly create the open source business of the Chinese people
ES6 deep - ES6 class class