简体   繁体   中英

Issue with NavigationBarTitle when scrolling List with TextFields inside of it

I have a simple checklist app that uses a SwiftUI List view to display sections with list items inside of it.

Because I want the list items to be editable, each list row has a TextField inside of it with the item name in it. However, if I focus into a text field and scroll the list before hitting the Return Key , the large navigationBarTitle has a bug where it remains frozen in place. For it to work properly, I have to back out of the page and come back.

I'm not seeing any errors, so I'm not sure why this occurring. I have a suspicion using a wrapped UITextField might solve this, but I'm not sure.

SwiftUI List with TextFields 滚动错误导航栏大标题粘性

I was able to fix my own issue while trying to create a reproducible example.

The bug was the result of a background color I was applying to the parent Group that contained the List . Removing the background color fixed my issue!

struct ChecklistView: View {
    var body: some View {
        Group {
            if empty {
                EmptyView()
            } else {
                ListView()
            }
        }
        .background(Color(.tertiarySystemBackground).edgesIgnoringSafeArea(.all)) // removing this line fixed my issue
        .navigationBarTitle("My title")
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM