小编The*_*Jof的帖子

SwiftUI:摆脱 SelectionManagerBox<String> 尝试每帧更新多次

我花了几个小时试图摆脱我的应用程序上的错误消息:

\n
List with selection: SelectionManagerBox<String> tried to update multiple times per frame.\n
Run Code Online (Sandbox Code Playgroud)\n

这是一款 macOS 14 应用程序。由于我无法找到解决方案,因此我决定尝试创建一个最小的可重现示例。这是这个例子:

\n
import SwiftUI\n\nstruct ContentView: View {\n    @State var selection: String = ""\n    @State var secondSelection: String = ""\n    \n    var body: some View {\n        NavigationSplitView {\n            List(selection: $selection) {\n                NavigationLink("A", value: "A")\n                NavigationLink("B", value: "B")\n                NavigationLink("C", value: "C")\n            }\n        } content: {\n            List(selection: $secondSelection) {\n                NavigationLink("1", value: "1")\n                NavigationLink("2", value: "2")\n                NavigationLink("3", value: "3")\n            }\n        } detail: {\n            Text("\\(selection) - \\(secondSelection)")\n        }\n …
Run Code Online (Sandbox Code Playgroud)

navigation swift swiftui

6
推荐指数
1
解决办法
768
查看次数

标签 统计

navigation ×1

swift ×1

swiftui ×1