没有使用SwiftUI显示的视图

2022-01-28 05:11:38 标签 iosswiftxcodemacosswiftui

我有列表和在表中单击任何单元格,它呈现新的视图,它最初是工作的。

我在每个单元格中都有删除选项,它将从列表中删除特定的单元格,当我删除任何单元格并在列表中单击其他单元格时,它不呈现视图。

有人知道问题出在哪里吗?

下面是展示表格的代码:

struct StoriesView: View {
    
    enum StoriesSheet: Identifiable {
        var id: Int {
            switch self {
            case .showStory:
                return 0
            case .addStory:
                return 1
            case .capturePicture:
                return 2
            case .editStory:
                return 3
            case .report:
                return 4
            }
        }
        
        case addStory(data: Data)
        case capturePicture(_ type: CaptureImageType)
        case showStory(_ story: Story)
        case editStory(_ story: Story)
        case report(_ story: Story)
    }
    
    @StateObject var viewModel = StoriesViewModel()
    
    @State var showRefreshView: Bool = false
    @State var showRefreshOnBottom: Bool = false
    @State var pullStatus: CGFloat = 0
    
    // Camera
    @State var showGetPictureActionSheet = false
    @State var currentSheet: StoriesSheet?
    
    
    var body: some View {
        
        RefreshableList(showRefreshView: $showRefreshView, pullStatus: $pullStatus, action: {
            viewModel.apply(.onRefresh)
        }, showRefreshOnBottom: $showRefreshOnBottom) {
            Group {
                if viewModel.shouldShowStories {
                    storiesList() .padding(.bottom, 80)
                        .listRowInsets(EdgeInsets())
                } else {
                    EmptyFeedView(imageName: "camera", description: "new_story_description", buttonText: "new_story") {
                        showGetPictureActionSheet = true
                    }.frame(minWidth: 0, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity, alignment: .center)
                    .padding()
                }
            }.sheet(item: $currentSheet, content: { sheet in
                getContent(for: sheet)
            })
        }
        .onAppear {
            viewModel.apply(.onRefresh)
        }.actionSheet(isPresented: $showGetPictureActionSheet, content: {
            getPictureActionSheet()
        }).navigationBarItems(leading: EmptyView(), trailing: CameraButton(didSelectType: { (type) in
            currentSheet = .capturePicture(type)
        }))
    }
    
    private func storiesList() -> StoriesListView {
        StoriesListView(storiesList: viewModel.storiesList) { story in
            self.viewModel.selectedStory = story
            currentSheet = .showStory(story)
        } didInteractWithStory: { (story, interaction) in
            interact(interaction, with: story)
        }
    }
    
    private func interact(_ interaction: StoryInteraction, with story: Story) {
        switch interaction {
        case .edit:
            currentSheet = .editStory(story)
        case .report:
            currentSheet = .report(story)
        }
    }
    private func getContent(for sheet: StoriesSheet) -> some View {
        switch sheet {
        case .showStory(let story):
            guard let selectedStory = viewModel.selectedStory else {
                return AnyView(StoryDetailView(story: story))
            }
            return AnyView(StoryDetailView(story: selectedStory))
        case .capturePicture(let type):
            return AnyView(ImagePicker(type: type) { (data) in
                if let data = data {
                    currentSheet = .addStory(data: data)
                } else {
                    currentSheet = nil
                }
            })
        case .addStory(let data):
            return AnyView(AddEditStoryView(viewModel: AddStoryViewModel(imageData: data)))
        case .editStory(let story):
            return AnyView(AddEditStoryView(viewModel: EditStoryViewModel(story)))
        case .report(let story):
            return AnyView(ReportReasonSelectionView(story))
        }
    }
    
    private func getPictureActionSheet() -> ActionSheet {
        return ActionSheet(
            title: Text("sheet_image_title").font(.system(.headline)),
            buttons: [cameraActionSheetButton(),
                      libraryActionSheetButton(),
                      .cancel()])
    }
    
    private func cameraActionSheetButton() -> Alert.Button {
        .default(Text("sheet_image_take_photo"), action: {
            currentSheet = .capturePicture(.camera)
        })
    }
    
     private func libraryActionSheetButton() -> Alert.Button {
        .default(Text("sheet_image_pick"), action: {
            currentSheet = .capturePicture(.photoLibrary)
        })
    }
}

请检查附件完整的代码显示故事。

任何帮助都将不胜感激。

提前谢谢。

阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码