ios 在SwiftUI中推送新视图时隐藏选项卡栏

6psbrbz9  于 2022-12-20  发布在  iOS
关注(0)|答案(2)|浏览(194)

通过NavigationLink推送新视图时,如何隐藏选项卡栏?
下面是我如何推动下一个视图:

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

xqk2d5yq1#

注意: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")
    }
}
4urapxun

4urapxun2#

在iOS 16中,您有此选项:

.toolbar(.hidden, for: .tabBar)

只需将其附加到要推送的视图。

相关问题