When you want to use NavigationLink to transition to the screen.

Asked 1 years ago, Updated 1 years ago, 410 views

If you use the following code when you want to transition with NavigationLink, you will get an error.Why?

error messages:

Cannot convert value of type 'String' to expected argument type'()->Label'

Current State Code:

struct ContentView:View {
    let fruits = ["Apple", "Orange", "Banana"]
    varbody:someView {
        List{
            Section {
                Text ("Daikon")
                Text ("Cabbage")
                Text ("Potato")
            } header: {
                Text("Yasai")
            }
            Section {
                ForEach(0..<fruit.count) {index in
                    NavigationLink (destination: AnotherView, label: {Text(fruits[index])})
                }
            } header: {
                Text ("Fruit")
            }
        }
    }
}

structure AnotherView:View {
    varbody:someView {
        Text ("Text")

swift xcode

2023-03-08 04:28

1 Answers

destination:AnotherView part to destination:{AnotherView()} will not work?


2023-03-08 05:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.