下面的代码在几个地方的示例中找到并且曾经为我工作,但现在它崩溃了。问题似乎出在 iPadOS 上,因为它似乎适用于 iPhone,包括模拟器和物理设备。
错误是:
'UIPopoverPresentationController (<UIPopoverPresentationController: 0x155e1b5f0>) 应该在演示发生之前设置一个非零的 sourceView 或 barButtonItem。以 NSException 类型的未捕获异常终止
这是 iPadOS 上的错误还是我做错了什么?
import SwiftUI
struct ContentView: View {
@State var showSheet = false
var body: some View {
Button(action: actionSheet)
{
Label("", systemImage: "square.and.arrow.up")
}
}
func actionSheet() {
let av = UIActivityViewController(activityItems: ["Testing"], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}