... to reuse a view with a navigationBarTitle? Or do I really have to repeat everything...just without navigationBarTitle for tvos?
#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
Try this approach
extension View {
public func iosnavigationBarTitle(_ title: Text,
displayMode: NavigationBarItem.TitleDisplayMode = .inline) -> some View {
#if os(iOS)
return self.navigationBarTitle(title, displayMode: displayMode)
#else
return self
#endif
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.