SwiftUI Toolbar Buttons Don’t Appear or Don’t Work

I am really struggling with Toolbar button issues. I have a fairly complicated app that uses a lot of Toolbar items throughout. Most work as expected.

However, there are two situations that are extremely frustrating. The first concerns placing a toolbar and button on the keyboard for a particular view. The app uses NavigationSplitView. In the main list I have a ToolbarItem that contains a menu to navigate to a screen to add an Item (a SwiftData model), and four other destinations(.topBarTrailing). This all works as expected most of the time. Occasionally the ToolbarItem will simply be missing. I need to hard close the app and reopen to be able to do anything.

Worse is my attempt to add a ToolbarItem to the keyboard. I have an @State var Bool to move to the screen to add a new Item and I want to add a ToolbarItem for that Add Item view to include a keyboard toolbar button to move through focus fields and a second keyboard toolbar button to dismiss the keyboard. If I use .fullScreenCover(isPresented:) the keyboard toolbar does not appear at all. If I use .sheet(isPresented:) the keyboard toolbar appears, the Dismiss button works but the Next navigation for changing focus fields does nothing at all.

I wrote a simple one view app with the same functionality and it works as expected. Here is the code:

struct KeyboardToolbarView: View {
    
    @Environment(.dismiss) var dismiss
    
    @State private var name: String = ""
    @State private var subject: String = ""
    @State private var count: String = ""
    @State private var value: String = ""
    
    @FocusState private var focusedField: Field?
    
    enum Field: Hashable {
        case name, subject, count, value
    }
    
    var body: some View {
        NavigationStack {
            VStack {
                VStack {
                    Form {
                        TextField("Name", text: $name)
                            .focused($focusedField, equals: .name)
                        
                        TextField("Subject", text: $subject, axis: .vertical)
                            .focused($focusedField, equals: .subject)
                        
                        TextField("Count", text: $count)
                            .keyboardType(.numberPad)
                            .focused($focusedField, equals: .count)
                        
                        TextField("Value", text: $value)
                            .keyboardType(.decimalPad)
                            .focused($focusedField, equals: .value)
                    }//form
                }
                Spacer()
                Button {
                    dismiss()
                } label: {
                    Text("Dismiss")
                }

            }
            .textFieldStyle(.roundedBorder)
            .padding()
            .toolbar {
                ToolbarItemGroup(placement: .keyboard) {
                    Button("Next") {
                        moveToNextField()
                    }
                    Button("Done") {
                        hideKeyboard()
                    }
                }
            }//toolbar
        }//nav
    }//body
    
    private func moveToNextField() {
        switch focusedField {
        case .name:
            focusedField = .subject
        case .subject:
            focusedField = .count
        case .count:
            focusedField = .value
        default:
            hideKeyboard()
        }
    }
    
    private func hideKeyboard() {
        UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}

If I add this exact view to my app and navigate to it from the main menu with .sheet(isPresented:) the functionality is as expected. If I navigate to it with .fullScreenCover(isPresented:) the keyboard toolbar does not appear at all.

For the most part – ALL of my screens have buttons in one or both .topBarLeading or .topBarTrailing. All work as expected with the exception of the quirk described above for the menu button (once in a while it does not appear).

Here is a ContentView that can demonstrate the menu system. Tap the menu then select a TextField – no keyboard toolbar. Sometimes typing in a field will raise the keyboard toolbar. Change the .fullScreenCover to .sheet and it usually works. In my full app it is even more erratic.

struct ContentView: View {
    
    @State private var showKeyboardToolbarView: Bool = false
    
    var body: some View {
        NavigationSplitView {
            VStack {
                Text("Sidebar View")
                List {
                    Text("One")
                    Text("Two")
                    Text("Three")
                }
                .fullScreenCover(isPresented: $showKeyboardToolbarView) {
                    KeyboardToolbarView()
                }
            }
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    Menu {
                        
                        Button(action: {
                            showKeyboardToolbarView = true
                        }, label: {
                            Label("Add New Item", systemImage: "plus")
                        })
                    } label: {//menu
                        Image(systemName: "ellipsis.circle")
                            .font(.system(size: 20))
                    }
                }
            }
        } detail: {
            Text("Detail View")
        }
    }
}

I would really appreciate some guidance. I’ve been using toolbar ToolbarItem and ToolbarItemGroup for a long time with no issues. Something changed. Xcode 15.4 iOS 17.5

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật