排除tvOS的navigationBarTitle的更好方法?

问题描述 投票:0回答:1

有没有比这更好的方法,可以通过NavigationBarTitle重用视图?还是真的要重复所有的事情……只是没有tvos的navigationBarTitle吗?

 #if os(iOS)

                        NavigationLink(
                            destination: CountryDetails(countryInfo: self.$userData.countryInfos[countryInfosIndex(of: country.name)])
                                .environmentObject(self.userData)
                                .navigationBarTitle(Text(country.name), displayMode: .inline) // <<<<<<<< the only difference
                        ) {
                            EmptyView() 
                        }.frame(width: 1, height: 1) 
 #else
                        NavigationLink(
                            destination: CountryDetails(countryInfo: self.$userData.countryInfos[countryInfosIndex(of: country.name)])
                                .environmentObject(self.userData)
                        ) {
                            // CountryRow(country: country)
                            EmptyView() 
                        }.frame(width: 1, height: 1) 
 #endif
ios swiftui tvos
1个回答
0
投票

尝试这种方法

extension View {
    public func iosnavigationBarTitle(_ title: Text, displayMode: NavigationBarItem.TitleDisplayMode) -> some View {
#if os(iOS)
        return self.navigationBarTitle(title, displayMode: displayMode)
#else
        return self
#endif
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.