当前位置:网站首页>Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
2022-07-05 16:40:00 【Knowledge fatness】
Apple Have been abandoned NavigationView, It was previously used to encapsulate the view stack , These views are essentially views pushed during rendering and popped up when closing . This is a iOS Navigation is a familiar way to use from the beginning , There is no physical back button , But there is a navigation bar at the top , There is a back button , It describes “ back off ” The location of .
There are two new ways to implement navigation , But they end up iPhone It looks very similar , The reason I will discuss later .
Let's get started !
NavigationStack
This application is very simple from several Hashable and Identifiable Structure began to .
Screen The enumeration that stores the navigation state must be Hashable, Because the new initialization program needs NavigationLink it , I'll use it later . In order to be Hashable The relevant value also needs to be Hashable. If they just String and an , This is still true Int, But I want to use ForEachwhich The required type is also Identifiable. As the original value type String also Int It's interchangeable , And they don't define their unique properties .
I have added data ContentView Is two arrays .
I can ( And probably should ) Use anObservableObject To store data , But I'd rather write more code to specifically demonstrate navigation .
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)边栏推荐
- 数据访问 - EntityFramework集成
- Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
- 【刷題篇】鹅廠文化衫問題
- 《21天精通TypeScript-3》-安装搭建TypeScript开发环境.md
- 一键安装脚本实现快速部署GrayLog Server 4.2.10单机版
- BS-XX-042 基于SSM实现人事管理系统
- JSON转MAP前后数据校验 -- 自定义UDF
- Google Earth Engine(GEE)——Kernel核函数简单介绍以及灰度共生矩阵
- ES6 drill down - Async functions and symbol types
- How to install MySQL
猜你喜欢
随机推荐
Practice independent and controllable 3.0 and truly create the open source business of the Chinese people
Some cognitive thinking
PHP 严格模式
The list set is summed up according to a certain attribute of the object, the maximum value, etc
[brush title] goose factory shirt problem
Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
程序员如何提升自己的格局?
[js] skill simplification if empty judgment
APICloud云调试解决方案
How to install MySQL
The database of the server is not connected to 200310060 "unknown error" [the service is up, the firewall is off, the port is on, and the netlent port is not connected]
10 minutes to help you get ZABBIX monitoring platform alarm pushed to nail group
不敢买的思考
The memory of a Zhang
ES6深入—async 函数 与 Symbol 类型
用键盘输入一条命令
What is the difference between EDI license and ICP business license
How to use FRP intranet penetration +teamviewer to quickly connect to the intranet host at home when mobile office
降本40%!Redis多租户集群的容器化实践
Mongodb getting started Tutorial Part 04 mongodb client









