xcode - 如何修复 TabView 中 NavigationView 中 List 下的灰色条?

标签 xcode swiftui uinavigationbar uitabbar swiftui-list

所以我遇到了一个问题,在我的列表下方出现一个灰色条,当我点击一个单元格转到另一个 View 时,有一个更大的灰色条。这是 ListView 的代码:

 VStack{
             NavigationView{
                VStack{



                List{
                    ForEach(answersArray.indices, id: \.self) { day in
                        NavigationLink(destination: DetailView(questions: self.answersArray[day].questions, answers: self.answersArray[day].answers, date: self.answersArray[day].dayDone.toString(dateFormat: "MM/dd/yy"))) {


                        HStack{
                            VStack{
                                ForEach(self.answersArray[day].questions.indices) { question in
                                    //Text(question)
                                    Text(self.answersArray[day].questions[question])
                                    .lineLimit(1)
                                        .frame(width: 250, height: 30, alignment: .leading)
                                      //  .padding(.vertical, 5)
                                    //.padding(.bottom)

                                }

                            }
                           // .truncationMode(.tail)
                            //.frame(minWidth: 0, idealWidth: 200, maxWidth: .infinity, minHeight: 0, idealHeight: 50, maxHeight: 75, alignment: .leading)

                            Text(self.answersArray[day].dayDone.toString(dateFormat: "MM/dd/yy"))
                                .frame(minWidth: 0, idealWidth: 50, maxWidth: .infinity, minHeight: 0, idealHeight: 20, maxHeight: 20, alignment: .trailing)
                        }

                        .padding(.horizontal, 5)
                    }

                        //.frame(minWidth: 0, idealWidth: 250, maxWidth: .infinity, minHeight: 0, idealHeight: 50, maxHeight: 100, alignment: .center)
                    }
                    //.colorMultiply(Color("Background Green"))
                  //  .listRowBackground(Color("Background Green"))
                    //.listRowBackground(Color("Background Green"))

                    Button(action: {
                        self.answersArray.append(DailyAnswer(questions: ["Question 1", "Question 2"], answers: ["I am happy", "I am sad"], dayDone: Date().addingTimeInterval(100000), lastWeek: false))
                        self.answersArray.append(DailyAnswer(questions: ["Question 1", "Question 2"], answers: ["I am happy", "I am sad"], dayDone: Date(), lastWeek: false))
                        self.answersArray.append(DailyAnswer(questions: ["Question 1", "Question 2"], answers: ["I am happy", "I am sad"], dayDone: Date(), lastWeek: false))
                    }) {
                        Text("Create cells")
                    }
                    }
                 .navigationBarTitle("Title")
               //.colorMultiply(Color("Background Green"))




                }

             }

             .accentColor(Color("My Gray"))

            }

这是单独 View 的代码:
import SwiftUI

struct DetailView: View {
    var questions : [String];
    var answers : [String];
    var date : String;
    var body: some View {

            //Color("Background Green")
               //.edgesIgnoringSafeArea(.all)

        NavigationView{
            ZStack{
            Color("Background Green")
                   .edgesIgnoringSafeArea(.all)
                ScrollView{
                    VStack{
                        ForEach(questions.indices) { pair in
                            Text(self.questions[pair])
                                .font(.title)
                                .padding()
                            Text(self.answers[pair])
                            .padding()
                                .font(.body)
                            .frame(minWidth: 0, idealWidth: 250, maxWidth: 350, minHeight: 150, idealHeight: 200, maxHeight: .infinity, alignment: .topLeading)
                            .background(
                            RoundedRectangle(cornerRadius: 5)
                                .stroke(Color.black, lineWidth: 1)
                            )

                        }

                    }
                    .padding(.top)
                    .navigationBarTitle("\(date)", displayMode: .inline)
                }

        }
        }
    }
}

List View

Other View

我也知道这看起来与 This Question 非常相似,但是当我在该页面上实现解决方案时,它只会更改顶部导航栏标题的颜色,而不是底部的灰色。

此外,这也是我为 Tab Bar 和 Navigation Bar 设置样式的地方
 init() {

       UINavigationBar.appearance().backgroundColor = UIColor(named: "Background Green")
       UITabBar.appearance().isTranslucent = false
       UITabBar.appearance().barTintColor = UIColor.black
       }

最佳答案

我看到堆栈中有很多 NavigationView:

 VStack{
             NavigationView{ // << here in first snapshot
                VStack{


        NavigationView{ // << here in second snapshot
            ZStack{

由于没有提供完整的代码,因此也可能有其他代码......

这是一个经验法则:在一个 View 层次结构链中必须只有一个根 NavigationView。因此,请确保将一个 NavigationView 放置为 Past Journals 选项卡的选项卡项根 View (同样,假设仅基于提供的代码)。

关于xcode - 如何修复 TabView 中 NavigationView 中 List 下的灰色条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61236579/

相关文章:

swift - 如何在 SwiftUI 中将通用 View 传递给结构体

ios - 将 backItem 放在 UI 导航栏的顶部

iphone - UINavigationBar 中的事件指示器

ios - 在 UIView 上方添加一个按钮

ios - Package.swift与Xcode 11 Project一起使用,如何同时使用Carthage和SPM?

swiftui - 是什么导致我的具有更高布局优先级的 SwiftUI View 占用所有空间?

swift - 为什么我很快得到 'X is not convertible to T.Y'?

ios - 导航栏标题更改

ios - 如何使用 IndexPathsForSelectedRows?

ios - 试图让 iOS 13 项目与 iOS 12 兼容