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

iOS 16中NavigationLink为何处于禁用状态?

列表项禁用状态

以下是导致NavigationLink处于禁用状态的几个常见原因及对应解决办法:

  • 未使用NavigationStack容器
    iOS 16的新导航API(NavigationLink(value:) + .navigationDestination)必须嵌套在NavigationStack内部才能正常工作,否则链接会失去交互能力。修正后的代码结构如下:

    NavigationStack {
        List(yourDataSource) { example in
            NavigationLink(value: example) {
                ListRowView(title: example.title, subtitle: example.subtitle)
            }
        }
        .navigationDestination(for: CollectionItem.self) { example in
            Text(example.title)
        }
    }
    
  • CollectionItem未遵循Hashable协议
    .navigationDestination要求绑定的数据类型必须遵循Hashable协议,否则无法正确匹配跳转目标。请确保你的CollectionItem结构体添加协议遵循:

    struct CollectionItem: Hashable {
        let title: String
        let subtitle: String
        // 其他自定义属性
    }
    
  • ListRowView内部禁用了交互
    检查ListRowView的实现代码,是否存在.disabled(true)或其他禁用用户交互的修饰符。如果有,移除该设置,或者调整逻辑仅在特定场景下禁用交互。

  • 数据源对象异常
    确认example对象不为nil,且title、subtitle等属性均有有效取值。若数据源为空或对象属性缺失,也可能导致链接无法响应点击。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 23:20:18