Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda