-1

这是我的列表视图:

struct ContentView: View {
    
    let colors: [Color] = [.red, .green, .yellow, .orange, .blue, .black, .pink, .purple, .gray]
    
    
    var body: some View {
        NavigationView {
            List {
                ForEach(colors, id: \.self) { color in
                    NavigationLink(destination: DetailView(color: color)) {
                        Text(color.name!)
                    }
                } 
            }
        }
    }
}

extension Color {
    var name: String? {
        switch self {
        case Color.red: return "red"
        case Color.green: return "green"
        case Color.yellow: return "yellow"
        case Color.blue: return "blue"
        case Color.orange: return "orange"
        case Color.black: return "black"
        case Color.pink: return "pink"
        case Color.purple: return "purple"
        case Color.gray: return "gray"
        default: return nil
        }
    }
}

和详细视图:

struct DetailView: View {
    
    var color: Color
    
    var body: some View {
        Circle()
            .foregroundColor(color)
    }
}

当从详细视图返回时,行覆盖如下所示:

在此处输入图像描述

知道为什么会这样吗?

4

1 回答 1

0

似乎这已在 iOS 14 Beta 5 中得到修复!

于 2020-08-22T05:21:18.980 回答