我尝试使用Xcode预览功能。当我直接在代码中添加视图时,它的效果很好,但是如果我通过情节提要添加任何视图,则预览将不会显示这些视图。这是我的代码:
import UIKit
final class ViewController: UIViewController {
@IBOutlet weak var segmentedControl: UISegmentedControl?
}
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct ViewControllerRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
return ViewController().view
}
func updateUIView(_ view: UIView, context: Context) {
}
}
@available(iOS 13.0, *)
struct ViewController_Preview: PreviewProvider {
static var previews: some View {
Group {
ViewControllerRepresentable()
}
}
}
#endif
那是我在模拟器和情节提要中的控制器:
这就是控制器在预览中的外观:
答案 0 :(得分:1)