ios - 在 SwiftUI 中推送新 View 时隐藏 TabBar

标签 ios swiftui

如何在通过 NavigationLink 推送新 View 时隐藏 TabBar?

这是我推送下一个 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 上出现异常

据我所知,这是一个重新布局,可以提供您所要求的效果。

然而,尽管下面的代码没有任何犯罪行为,但在 UIKit 的导航返回内部发生了异常:

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

关于ios - 在 SwiftUI 中推送新 View 时隐藏 TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58891188/

相关文章:

ios - 如何在 Swift 中使用 YouTube Api v3 正确检查 UIImage 是否为零?

text - SwiftUI-文本minimumScaleFactor不会仅在需要时缩放

swift - 新的 iOS 开发者应该使用 Storyboard 和 Xibs/Nibs 吗?

swiftui - 在初始化所有存储的属性之前使用“self”错误 SwiftUI

ios - 使用 http 和 https 移动网络服务

ios - 从基类或协议(protocol)继承的静态字段 - 如何?

ios - 无法注册推送通知

iphone - UIFont字体带名称: residing on heap and never destroyed

swift - 在 SwiftUI 中以编程方式自动聚焦 TextField

SwiftUI:如何制作 Lottie 动画循环?