0

In my Apple Watch app, I update the title text via self.setTitle("some title"). The problem is, that if that code gets triggered on Controller A while Controller B is present, A, the one in the "background", (e.g. in a hierarchical/Master-Detail design) changes the title although B is showing.

What's the best way to get around this? I tried looking for a way to do something like

if (self.navigationController.topViewController == self) {
        self.setTitle("Chats (live)")
}

but this isn't available on Watchos.

How else can I achieve this?

Xcodian Solangi
  • 2,342
  • 5
  • 24
  • 52
user2875404
  • 3,048
  • 3
  • 25
  • 47

1 Answers1

0

I put this together, haven't tested this much yet but on the first look it appears to work:

var masterTitle = ""
var masterActive = false

...

setControllerTitle("Test")           //set the title

override func didAppear() {
    masterActive = true              //enables title updates
    setControllerTitle(masterTitle)  //sets title if view re-appeared
}

override func willDisappear() {
    masterActive = false             //disables title updates
}

func setControllerTitle(_ s : String){
    masterTitle=s                    //saves title for future use
    if(masterActive){
        self.setTitle(s)             //sets title when view is current
    }
}
user2875404
  • 3,048
  • 3
  • 25
  • 47