Michael Rowe
Michael Rowe

Reputation: 956

Why am I losing my SwiftUI View when switching screens

I have an SwiftUI based native WatchOS app. I have 4 views that the user can swipe left and right to get to. This feature is not directly a SwiftUI feature so I am using WKInterfaceController.reloadRootConrollers(withNamesandContext:) However the screen sometimes just loads a blank screen when swiping. I don't see anything wrong in this code...

import WatchKit
import Foundation
import SwiftUI

class HostingController : WKHostingController<MeetingView> {
    override init(){
        super.init()

        displayViews()
    }

    func displayViews() {
        WKInterfaceController.reloadRootControllers(withNamesAndContexts: [
            (name: "OneViewController", context: [:] as AnyObject),
            (name: "TwoViewController", context: [:] as AnyObject),
            (name: "ThreeViewController", context: [:] as AnyObject),
            (name: "FourViewController", context: [:] as AnyObject),
        ])
    }

    override var body: MainView {
        return MainView()
    }
}

Upvotes: 0

Views: 282

Answers (2)

Michael Rowe
Michael Rowe

Reputation: 956

Appears to have been a WatchOS bug... it is no longer a problem.

Upvotes: 0

Vladislav Vodicka
Vladislav Vodicka

Reputation: 161

Same problem here. Happens also while using storyboard.

Upvotes: 1

Related Questions