【发布时间】:2020-12-09 15:44:17
【问题描述】:
我有一个 UIViewController,它通过我的 viewDidLoad 中的一个函数呈现一个函数:
let imageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFit
return iv
}()
func configureViewComponents() {
view.addSubview(imageView)
这样称呼它:
override func viewDidLoad() {
super.viewDidLoad()
configureViewComponents()
}
我在单独的文件 form.swift 中有一个表单:
import Combine
import SwiftUI
struct myForm: View {
@ObservedObject var submission = Submission()
@State var confirmationMessage = ""
@State var showingConfirmation = false
var body: some View {
NavigationView {
Form {
Toggle(isOn: $submission.fieldOne ) {
Text("Field One")
}
我正在尝试将它添加到我的 UIViewController 中,就像我使用 view.addSubview(myForm) 添加我的 imageView 但我收到了消息 cannot convert value of type form to expected argument type UIView.
如何在这个 UIViewController 中展示我的表单?
【问题讨论】: