【发布时间】:2020-04-23 07:33:51
【问题描述】:
我正在尝试在 SwiftUI View 中实现一个选中标记的操作表。我正在使用一个
UIViewControllerRepresentable 创建一个UIAlertController
struct WhatsAppAlertController: UIViewControllerRepresentable {
let viewModel: PropViewModel
func makeUIViewController(context: Context) -> UIAlertController {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let contactsNumbers = viewModel.contactsNumbers()
for number in contactsNumbers {
let action = UIAlertAction(
title: "\(number.value.stringValue)",
style: .default,
handler: { _ in
self.viewModel.openWhatsAppURL(withNumber: number.value.stringValue)
})
alert.addAction(action)
}
let cancel = UIAlertAction(title: L10n.cancel, style: .cancel, handler: nil)
alert.addAction(cancel)
return alert
}
func updateUIViewController(_ uiViewController: UIAlertController, context: Context) {
}
}
它是使用显示的
.sheet(isPresented: $showWhatsAppActionSheet) {
WhatsAppAlertController(viewModel: self.viewModel)
}
我感觉这是因为 UIAlertController 是使用 .sheet 呈现的
我的计划是使用action.setValue(true, forKey: "checked") 勾选并记住所选选项。
有没有办法解决这个问题?或者也许只使用 SwiftUI 实现复选标记?
【问题讨论】:
-
This post 可能会有所帮助。
-
谢谢!设法修复它。
标签: swift swiftui uialertcontroller swiftui-actionsheet