小编mur*_*adi的帖子

切换列表中的选择 - SwiftUI

我希望我能清楚地解释我的问题。

我想通过切换从列表中选择一些课程,但无论我尝试过什么,它都不起作用。

我应该做些什么?

感谢您的时间。最好的,穆拉特

struct SubjectCardsView: View {
    // MARK: - Properties
    @State var courses: [Course] = Bundle.main.decode("courses.json")
    
    @State private var toggle: Bool = false
    
    // MARK: - Body
    var body: some View {
        
        NavigationView {
            
            List {
                
                ForEach(courses) { course in
                    Section(header: Text(course.title).font(.system(size: 15, weight: .medium, design: .rounded)).foregroundColor(.blue)) {
                        ForEach(course.courseName, id: \.name) { item  in
                            Toggle(isOn: $toggle, label: {
                                Text(item.name)
                            })
                            
                        }
                    }
                }
            }
            
            .listStyle(InsetGroupedListStyle())
            .navigationBarTitle("Choose your subject", displayMode: .inline).font(.system(size: 16, weight: .medium, design: .rounded))
            .navigationBarItems(leading: Button(action: { …
Run Code Online (Sandbox Code Playgroud)

foreach toggle swift swiftui

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

标签 统计

foreach ×1

swift ×1

swiftui ×1

toggle ×1