简体   繁体   English

不同 UI 元素的 SwiftUI 列表 - 失败

[英]SwiftUI list of different UI elements - fail

I'm trying to present a list, of witch the first item is a NavigationLink , because its configuration needs some extra options to be defined.我正在尝试提供一个列表,其中第一项是NavigationLink ,因为它的配置需要定义一些额外的选项。 All other operations can be run w/o special parameters.所有其他操作都可以在没有特殊参数的情况下运行。

(Code stripped down a bit): (代码精简了一点):

let operations = ["start", "stop", "set_marker", "save_map", "get_status"]    

NavigationView {
    VStack {
        Form {
            Section(header: Text("Header")) {
                List(operations, id: \.self) { operation in
                    if operation == "start" {
                        NavigationLink(destination: DetailView(operation: operation)) {
                            Text(operation.uppercased())
                        }
                    } else {
                        Button(action: {
                            switch operation {
                            case "stop":
                                break
                            default:
                                break
                            }            
                        }) {
                            Text(operation.uppercased()).foregroundColor(.black)
                        }
                    }
                }
            }
        }
    }
}

The thing compiles fine and displays fine too.这东西编译得很好,显示也很好。 At runtime I can click all "plain buttons" and it works.在运行时,我可以单击所有“普通按钮”并且它可以工作。 For the "start" entry I can open the second window just once.对于“开始”条目,我只能打开第二个窗口一次。 After return the "start" button does not react anymore.返回后“开始”按钮不再反应。 Any ideas?有任何想法吗?

在此处输入图片说明

Disregard.漠视。 Seems to be an issue on emulator and in preview only.似乎是模拟器和预览版的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM