校舎とフロアに関するアプリを作成しており、ナビゲーション ビューを使用していますが、公開インジケーターを表示したくないため、ナビゲーション リンクの幅を 0 に設定し、不透明度も設定する「ハック」を見つけました。最後のNavigationLinkでも実行したい場合、アプリは初期化中に不正なアクセスでApp Delegateファイルでクラッシュします。HStack を使用せず、最後の項目でこの「ハック」を行うと、他のリスト行のように見えますが、何も実行されません。それが機能する唯一の方法は、次のビューがナビゲーション リンク内にある場合です。これにより、ホーム画面の最後のリスト行が異なって表示されます。何か案は?どうもありがとうございました。
import SwiftUI
struct BuildingsView: View {
init() {
UITableView.appearance().separatorStyle = .none
}
var body: some View {
NavigationView {
List {
HStack{
BuildingCardView(titleString: "Námestie J. Herdu", subtitleString: "Námestie J. Herdu 2, Trnava", imageString: "namjherdu", infoString: "Rektorát, FMK, FF, FPV, internáty, jedáleň, kancelárie")
NavigationLink(destination: NamJHerduView()) {
EmptyView()}
.frame(width: 0)
.opacity(0)
}
HStack {
BuildingCardView(titleString: "Hajdóczyho", subtitleString: "Jána Hajdóczyho 1, Trnava", imageString: "hajdoczy", infoString: "Knižnica, učebne, kancelárie, Kino OKO")
NavigationLink(destination: HajdoczyhoView()) {
EmptyView()}
.frame(width: 0)
.opacity(0)
}
HStack {
BuildingCardView(titleString: "Bučianska", subtitleString: "Bučianska 4A, Trnava", imageString: "bucianska", infoString: "FSV, FMK, aula, kancelárie")
NavigationLink(destination: BucianskaView()) {
EmptyView()}
.frame(width: 0)
.opacity(0)
}
HStack {
BuildingCardView(titleString: "V Jame", subtitleString: "V Jame 3, Trnava", imageString: "vjame", infoString: "FMK, FSV, jedáleň")
NavigationLink(destination: VJameView()) {
EmptyView()}
.frame(width: 0)
.opacity(0)
}
HStack {
BuildingCardView(titleString: "Skladová", subtitleString: "Skladová 3, Trnava", imageString: "skladova", infoString: "FMK")
NavigationLink(destination: SkladovaView()) {
EmptyView()}
.frame(width: 0)
.opacity(0)
}
NavigationLink(destination: SpacinceView()) {
BuildingCardView(titleString: "Špačince", subtitleString: "Hlavná 6, Špačince", imageString: "spacince", infoString: "FPV, výskumné laboratóriá")}
}
.navigationBarTitle(
Text("Budovy UCM"), displayMode: .large).navigationBarHidden(false)
}
}
}
import SwiftUI
struct BuildingCardView: View {
let titleString: String?
let subtitleString: String?
let imageString: String?
let infoString: String?
init(titleString: String? = "null", subtitleString: String? = "null", imageString: String? = "default", infoString: String? = "null"){
self.titleString = titleString
self.subtitleString = subtitleString
self.imageString = imageString
self.infoString = infoString
}
var body: some View {
VStack {
Image(imageString!)
.resizable()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 150, alignment: .topLeading)
HStack {
VStack(alignment: .leading) {
Text(titleString!)
.font(.title)
.fontWeight(.black)
.foregroundColor(.primary)
.lineLimit(1)
Text(subtitleString!)
.font(.headline)
.foregroundColor(.secondary)
.lineLimit(3)
Text(infoString!)
.font(.subheadline)
.foregroundColor(.secondary)
.lineLimit(3)
}
.layoutPriority(100)
Spacer()
}
.padding()
}
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color(.sRGB, red: 150/255, green: 150/255, blue: 150/255, opacity: 0.2), lineWidth: 1)
)
}
}
import SwiftUI
struct ContentView: View {
var body: some View {
TabView{
BuildingsView()
.tabItem {
Image(systemName: "house")
Text("Budovy")
}
Text("Vyhľadávanie TBD")
.tabItem {
Image(systemName: "magnifyingglass")
Text("Vyhľadávanie")
}
MapView()
.tabItem {
Image(systemName: "map")
Text("Mapa")
}
}
}
}