【发布时间】:2021-02-16 10:15:40
【问题描述】:
我正在将一些 SwiftUI 视图实现到现有的 UIKit 应用程序中。 DashboardView(下图)是一个主屏幕,然后我需要推送到现有的 UIKit ViewControllers。我正在尝试将视图控制器推送到导航堆栈(即使用后退按钮,而不是模态)。下面的代码,显示更多按钮下的推送按预期工作,使用后退按钮推送到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
}
}
}
}
}
【问题讨论】:
-
您会准备最小的可重现示例还是授予项目访问权限?在这个快照中复制的东西太多了。
标签: ios swift swiftui uinavigationcontroller pushviewcontroller