在SwiftUI中推送新视图时隐藏TabBar [英] Hide TabBar when a new view is pushed in SwiftUI

查看:753
本文介绍了在SwiftUI中推送新视图时隐藏TabBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过NavigationLink推送新视图时,如何隐藏TabBar?

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

这是我推送下一个视图的方式:

Here's how I push the next View:

TabView {
    NavigationView {
        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")
    }
}

推荐答案

警告:在Xcode 11.2/iOS 13.2上引发异常

据我所知,这里是一个中继,可以提供您要求的效果.

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

但是,尽管下面的代码中没有任何犯罪内容,但在导航UIKit的内部时却遇到了异常:

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 

方法代码

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")
    }
}

这篇关于在SwiftUI中推送新视图时隐藏TabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆