Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Swift Key window subview disappearing

I am experiencing some weird behavior with a button I am trying to implement in my app. I have a 'compose post' button that I am adding to the key window of the app. I want to create the button and hide it in certain scenarios like when the navigation controller pushes a new view controller (i.e. clicking on a post). The app is setup like this:

Main is a storyboard that is a custom UITabController of type MainTabViewController that has 4 tabs, each a UINavigationController that has a container that is of type BaseViewController.

In the viewDidLoad function of MainTabViewController I create the compose button and add it to the key window as a subview like this:

 func createButton(){
        let keyWindow = UIApplication.shared.keyWindow
        postButtonContainer = FanMenu...
        keyWindow?.addSubview(postButtonContainer)
 }
    

And in BaseViewController I use viewWillDisappear to hide the compose button (i.e. when post is clicked on) and then viewWillAppear to show the compose button by setting the isHidden to true or false.

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    ComposeButtonManager.shared.hidePostButton()
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    ComposeButtonManager.shared.showPostButton()
}

The issue is happening only after I crash close the app after booting up from Xcode. What's happening is that when I reopen after crash closing - the app will load fine and present the compose button, but if I navigate from a tab and then back to that same tab, the compose button is not showing. And if I click a post and navigate back to BaseViewController subclass the button will re appear. I am not sure why the button is hiding after the tab bar switches, when all the UIViewControllers call to unhide the button when their view will appear.

When I run the project on my phone from Xcode, I can switch around tabs and the button won't disappear, its only happening after I crash close and disconnect from Xcode, not sure why this is happening.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda