如何将多个导航链接嵌入到单个列表行中?
我正在尝试复制类似苹果提醒应用程序的东西,其中有一些“块”(今天、计划、全部和标记),但我所有的尝试都以 XCode 告诉我它遇到导航问题结束。我现在使用的是 XCode 13.2.1 和 iOS 15.2。
如何让每个块导航到自己的目的地并阻止应用程序因 NavigationLink 错误而阻塞?
这是我的代码:
struct ContentView: View {
var body: some View {
NavigationView {
List {
Section(header: Text("Primary Section")) {
NavigationLink(destination: Text("First")) {
Label("First", systemImage: "1.circle")
}
Label("Second", systemImage: "2.circle")
Label("Third", systemImage: "3.circle")
}
Section(header: Text("Block Section")) {
VStack (spacing: 20) {
HStack (spacing: 20) {
Blocks(title: "1")
Blocks(title: "2")
}
HStack (spacing: 20) {
Blocks(title: "3")
Blocks(title: "4")
}
}
.foregroundColor(Color.blue)
.frame(height: 160)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowBackground(Color.clear)
}
Section(header: Text("Lower Section")) {
NavigationLink(destination: Text("Lower First")) {
Label("First", systemImage: "1.circle")
}
Label("Second", systemImage: "2.circle")
Label("Third", systemImage: "3.circle")
NavigationLink(destination: Text("Lower Fourth")){
Label("Fourth", systemImage: "4.circle")
}
}
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitle(Text("Catalogue"), displayMode: .large)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct Blocks: View {
let title: String
var body: some View {
ZStack {
NavigationLink(
destination: Text(title)) {
EmptyView()
}
.opacity(0)
RoundedRectangle(cornerRadius: 12, style: .continuous)
Image(systemName: "\(title).circle.fill")
.foregroundColor(.white)
.imageScale(.large)
}
}
}```
I'm trying to replicate something like Apple's Reminders app where there are some "blocks" (Today, Scheduled, All and Flagged), but all my attempts end in XCode telling me its encountering navigation issues. I'm using XCode 13.2.1 and iOS 15.2 right now.
How can I get each bock to navigation to its own destination and stop the app from choking on the NavigationLink errors?
Here is my code:
struct ContentView: View {
var body: some View {
NavigationView {
List {
Section(header: Text("Primary Section")) {
NavigationLink(destination: Text("First")) {
Label("First", systemImage: "1.circle")
}
Label("Second", systemImage: "2.circle")
Label("Third", systemImage: "3.circle")
}
Section(header: Text("Block Section")) {
VStack (spacing: 20) {
HStack (spacing: 20) {
Blocks(title: "1")
Blocks(title: "2")
}
HStack (spacing: 20) {
Blocks(title: "3")
Blocks(title: "4")
}
}
.foregroundColor(Color.blue)
.frame(height: 160)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowBackground(Color.clear)
}
Section(header: Text("Lower Section")) {
NavigationLink(destination: Text("Lower First")) {
Label("First", systemImage: "1.circle")
}
Label("Second", systemImage: "2.circle")
Label("Third", systemImage: "3.circle")
NavigationLink(destination: Text("Lower Fourth")){
Label("Fourth", systemImage: "4.circle")
}
}
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitle(Text("Catalogue"), displayMode: .large)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct Blocks: View {
let title: String
var body: some View {
ZStack {
NavigationLink(
destination: Text(title)) {
EmptyView()
}
.opacity(0)
RoundedRectangle(cornerRadius: 12, style: .continuous)
Image(systemName: "\(title).circle.fill")
.foregroundColor(.white)
.imageScale(.large)
}
}
}```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论