Monday, October 19, 2026
HomeiOS Developmentios - SwiftUI View inside UIView

ios – SwiftUI View inside UIView

[ad_1]

I’m making an attempt to inject a SwiftUI view within a UIView, and it’s exhibiting my SwiftUI view however the body is method off and I can’t work out why.

UPDATE: After dismissing the view controller and reloading it once more, the SwiftUI view is loaded/introduced completely, why is that?

That is my SwiftUI View:

@obtainable(iOS 14.0, *)
struct AvailablePointsSummary: View {
    
    @State personal var factors: PointsResponse? = nil
    
    var physique: some View {
        if let factors = factors {
            GroupBox(
                label:  SummaryLabelView(labelText: "Accessible Factors")
            ) {
                SummaryRow(title: "Money Factors", quantity: Float(factors.cashoutPoints).withCommas())
                SummaryRow(title: "Promo Factors", quantity: Float(factors.availablePromoPoints ?? 0).withCommas())
            }
            .body(width: 380, peak: 160)
        } else {
            Textual content("Loading...")
                .onAppear {
                    getPoints()
                }
        }

    }
    
    func getPoints() {
        PointsService().getPointsResponse { factors in
            DispatchQueue.important.async {
                self.factors = factors
            }
        }
    }
    
}

@obtainable(iOS 14.0, *)
var availPointsSummary = UIHostingController(rootView: AvailablePointsSummary())

Setup in my UIViewController

func setupAvailablePoints(){
        let pointView = availPointsSummary.view
        pointView?.translatesAutoresizingMaskIntoConstraints = false
        pointView?.body = CGRect(x: 0, y: 0, width: 380, peak: 160)
        
        self.availPointsView.addSubview(pointView!)
        self.addChild(availPointsSummary)
    }

enter image description here

And the outcome
enter image description here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments