我创建了自定义警报,但当我尝试在.sheet View上显示它时,出现了此错误-
2023-08-05 00:21:15.880778+0200 MyApp[759:72430] [演示]尝试<TtGC7SwiftUI19UIHostingControllerV6Events11CustomAlert: 0x108009600>在<TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x103022800>(来自<TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x103022800>)已在演示的内容上演示<TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x10680a000>。
这是我的代码
extension View {
func customAlert(args) -> some View {
if let topController = UIApplication.shared.windows.first?.rootViewController {
let alert = CustomAlert(args)
let hostingController = UIHostingController(rootView: alert)
hostingController.modalPresentationStyle = .overFullScreen
hostingController.modalTransitionStyle = .crossDissolve
hostingController.view.backgroundColor = .clear
topController.present(hostingController, animated: false)
}
return self
}
}
字符串
我该怎么修呢?
请帮帮我!我现在不知道,为什么会发生:)
1条答案
按热度按时间n3h0vuf21#
.sheet
修饰符在当前窗口的根视图控制器上显示一个视图控制器。当我们需要在已经呈现的视图控制器上呈现一个视图控制器时,我们可以使用UIViewController
的presentedViewController
属性来检查根视图控制器是否已经呈现了任何VC。字符串