Hide TabBar when a new view is pushed in SwiftUI

前端 未结 1 1331
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 11:01

how can I hide the TabBar when a new View is pushed via NavigationLink?

Here\'s how I push the next View:

T         


        
相关标签:
1条回答
  • Caution: rise exception on Xcode 11.2/iOS 13.2

    Here is a relayout which gives an effect you requested, as far as I understood.

    However, although there is nothing criminal in below code, on navigate back internals of UIKit got into exception:

     2019-11-24 10:54:36.644037+0200 Test[1180:41920] *** Terminating
    app due to  uncaught exception 'NSInternalInconsistencyException',
    reason:  'Tried to pop to a view controller that doesn't exist.'
    
    *** First throw call stack: (     0   CoreFoundation                      0x00007fff23c4f02e __exceptionPreprocess + 350  1   libobjc.A.dylib   
    0x00007fff50b97b20 objc_exception_throw + 48  2   CoreFoundation      
    0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88    3  
    Foundation                          0x00007fff256c9b61
    -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191     4  
    UIKitCore                           0x00007fff4713d9d1
    __57-[UINavigationController popToViewController:transition:]_block_invoke + 620 

    Approach code

    var body: some View {
        NavigationView {
            TabView {
                List(fakeUser) { user in
                    NavigationLink(destination: ChatDetailView(user: user)) {
                        ChatCell(user: user)
                    }
                }
                .navigationBarTitle("Chats")
                .navigationBarItems(leading: leadingBarItem, trailing: trailingBarItem)
                .tabItem {
                    Image(systemName: "message.fill")
                        .font(.system(size: 20))
                    Text("Chats")
                }
            }
            .navigationBarTitle("Chats")
        }
    }
    
    0 讨论(0)
提交回复
热议问题