【问题标题】:SwiftUI unlimited TabView itemSwiftUI 无限 TabView 项
【发布时间】:2021-07-31 13:07:42
【问题描述】:

我收到了 50 个关于 Firebase 的问题。我在作为自定义准备的 TabView 中使用 ForEach 返回此数据。但是从第23个问题,我看不到其他问题。我无法前进到下一页。这是什么原因? TabView中的物品不能无限退吗?

动图:

TabView 分页视图:

struct PagingQuestionView: View {
    var tests: [Test] = []
    @State var imageUrl: String = ""
    var storage = Storage.storage().reference()
    @ObservedObject var pagingQuestionOptionConfigure: PagingQuestionOptionConfigure = PagingQuestionOptionConfigure()
    var body: some View {
        GeometryReader { proxy in
            TabView(selection: $pagingQuestionOptionConfigure.pageIndex) {
                ForEach(tests, id: \.self) { item in
                    VStack(spacing: 20) {
                        EmptyView()
                            .frame(width: 350, height: 250)
                            .padding()
                        VStack {
                            Text("\(item.id))")
                            Text("\(item.question)")
                                .padding()
                        }
                        PagingOptionView(options: item.sections)
                    }
                    .tag(item.id)

                }
                .rotationEffect(.degrees(-90))
                .frame(width: proxy.size.width, height: proxy.size.height)
            }
            .frame(width: proxy.size.height, height: proxy.size.width)
            .rotationEffect(.degrees(90), anchor: .topLeading)
            .offset(x: proxy.size.width)
            .modifier(TabViewModifier())
        }
    }
}

TabViewModifier:

struct TabViewModifier: ViewModifier {

    @ViewBuilder
    func body(content: Content) -> some View {
        if #available(iOS 14.0, *) {
            content
                .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
                
        } else {
            content
        }
    }
}

【问题讨论】:

    标签: foreach swiftui tabview


    【解决方案1】:

    我解决了我的问题。 我在 ForEach 中添加了这个

    ForEach(tests.indices, id: \.self){ ... }
    

    【讨论】:

      猜你喜欢
      • 2020-07-12
      • 2021-03-27
      • 2021-02-19
      • 2021-10-17
      • 2022-01-20
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多