我正在将一些SwiftUI视图实现到一个现有的UIKit应用程序中。下面的DashboardView
是一个主屏幕,然后我需要推入现有的UIKit ViewControllers
。我尝试将View Controllers推入导航堆栈(即带有返回按钮,而不是模式化)。下面的代码,在“显示更多”按钮下的推送按预期工作,将SkateListViewController
推入并带有返回按钮,但在WorkoutListView
中推送的呈现视图控制器却是模态的?这是否与WorkoutListView
嵌入在父视图中有关?
struct DashboardView: View {
var body: some View {
ScrollView {
VStack(spacing: 7.0) {
HStack {
Text("Workouts")
.font(.custom(futuraBold, size: largeTitleTextSize))
.padding(.leading)
Spacer()
Button(action: {
let storyBoard: UIStoryboard = UIStoryboard(name: "Version3", bundle: nil)
let skateListTVC = storyBoard.instantiateViewController(withIdentifier: "skateListVC") as! SkateListTableViewController
UIApplication.topViewController()?.navigationController?.pushViewController(skateListTVC, animated: true) //This line works as expected and pushes onto Nav Stack with back button
}) {
Text("Show More")
.font(.custom(futuraMedium, size: headlineTextSize))
.foregroundColor(Color.blue)
}
}
ZStack {
VStack(alignment: .leading) {
WorkoutListView(workouts: [MockWorkout().getMockWorkout()])
}
.padding(.horizontal)
}
}
}
}
}
}
struct WorkoutListView: View {
@State var workouts: [HKWorkout]
var body: some View {
VStack(alignment: .leading) {
ForEach(workouts) { workout in
WorkoutRow(workout: workout)
.onTapGesture {
SelectedWorkoutSingleton.sharedInstance.selectedWorkout = workout
let storyBoard: UIStoryboard = UIStoryboard(name: "Version3", bundle: nil)
let skateDetailHostingControllerView = storyBoard.instantiateViewController(withIdentifier: "skateDetailHostingController") as! SkateDetailHostingController
UIApplication.topViewController()?.navigationController?.pushViewController(skateDetailHostingControllerView, animated: true) //This line shows Hosting Controller as Modal, doesn't push
}
}
}
}
}