07:SwiftUI-EditButton

 

 

正文

//
//  EditButtonPage.swift
//  SwiftUIDeom
//
//  Created by zhoukang03 on 2023/3/27.
//
// 7: 编辑按钮

import SwiftUI
import Combine

struct EditButtonPage: View {
    @ObservedObject private var source = dataSource()

    var body: some View {
        List {
            ForEach(source.items, id: \.self) { index in
                PageRow(title: "\(index)")
                    
            }
            .navigationBarItems(trailing: EditButton())
            
        }.navigationTitle(Text("编辑按钮")) // 导航标题
    }
}

class dataSource: ObservableObject {
    
    public var didChange = PassthroughSubject<Void, Never>()

    public var items: [Int] {
        didSet {
            didChange.send(())
        }
    }
    
    init() {
        self.items = (0..<10).map { $0 }
    }
}

#if DEBUG
struct EditButtonPage_Previews: PreviewProvider {
    static var previews: some View {
        EditButtonPage()
    }
}
#endif

 

posted on 2023-03-27 20:07  风zk  阅读(65)  评论(0编辑  收藏  举报

导航