You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

嵌入模态表单的NavigationLink点击无响应问题求助

问题分析与解决方案

你的问题根源在于视图层级嵌套错误:当把SecondView嵌入模态表单(如sheet中的Form)时,NavigationStack被嵌套在了Form内部,导致NavigationLink的交互被上层容器拦截,无法触发跳转。

修复方案

方案1:让SecondView直接作为模态根视图

如果你的模态只需要展示SecondView的内容,直接将SecondView作为sheet的内容即可,无需额外嵌套Form(因为List本身已经具备表单样式的布局):

// 示例:主视图中触发模态的代码
struct ContentView: View {
    @State private var showModal = false
    
    var body: some View {
        Button("打开模态视图") {
            showModal = true
        }
        .sheet(isPresented: $showModal) {
            SecondView() // 直接传入SecondView,它内部已有NavigationStack
        }
    }
}

方案2:调整层级,让NavigationStack包裹模态表单

如果必须在模态中使用Form容器,需要将NavigationStack作为模态的根视图,把Form放在NavigationStack内部,而非反过来嵌套:

// 修改模态内容结构
.sheet(isPresented: $showModal) {
    NavigationStack {
        Form {
            Section {
                NavigationLink(destination: Powerup()) {
                    Text("2")
                }
            }
        }
    }
}

额外优化点

  • iOS 16+的NavigationStack已不再需要isDetailLink(false)修饰符(该修饰符是针对旧版NavigationView的分栏布局设计的),可以直接移除,避免冗余代码干扰。
  • 检查Powerup视图的定义是否完整,确保它是一个符合View协议的有效视图。

内容的提问来源于stack exchange,提问作者helloimbrando

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 21:45:38