iOS 18开发者测试版中NavigationLink点击无响应问题求助
在iOS 18开发者测试版测试应用时,发现某一个NavigationLink组件点击无响应。该组件在之前所有iOS版本中均可正常运行,属于iOS 18特有问题。应用内其他NavigationLink组件在iOS 18上仍能正常工作,推测当前视图层级存在问题。点击该NavigationLink时无任何动画或反馈,应用完全无响应。
包含NavigationLink的SwiftUI结构体
struct TimelineScrollableListView: View { @ObservedObject var viewModel: TimelineViewModel var type: TimelineType var body: some View { ScrollViewReader { proxy in ScrollView { VStack(spacing: 0) { ForEach(viewModel.timelineRows) { timelineRow in switch (timelineRow) { case .Data(let calculation): let isSameDateAsToday = timelineRow.isSameDay(as: viewModel.dateToday) let contentView = ContentView( type: type, calculations: calculation, showBalanceForToday: viewModel.showBalanceOnToday, responseBalanceType: viewModel.responseBalanceType ) let timelineRowView = TimelineRowView( date: calculation.date!, isHighlighted: isSameDateAsToday, contentView: contentView, showRightArrow: viewModel.canNavigateToHistory ) .id(isSameDateAsToday ? "today" : timelineRow.id) if viewModel.canNavigateToHistory { NavigationLink { HistoryViewController.SwiftUI(date: calculation.date!) } label: { timelineRowView } } else { timelineRowView } case .Separator(let date): TimelineMonthSeparatorView(text: date.formattedText(format: "MMM. yyyy")) } } } } .onAppear { viewModel.adjustTodaysDateIfNeeded() DispatchQueue.main.async { proxy.scrollTo("today", anchor: .center) } TimelinesHostingViewController.ViewMediator.shared.onTodayButtonPressed = { withAnimation { proxy.scrollTo("today", anchor: .center) } } } } }
UIKit视图封装代码
跳转的HistoryViewController基于UIKit开发,通过以下结构体封装为SwiftUI可用组件:
struct SwiftUI: UIViewControllerRepresentable { var date: DateInRegion func makeUIViewController(context: Context) -> some UIViewController { return HistoryViewController(date: date) } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { } }
导航栈截图

内容的提问来源于stack exchange,提问作者Guy
相关产品推荐
相关产品推荐

