2

I am trying to call the method below that was declared in the superclass from its subclass. However, inside the method self.navigationController became nil. The superclass's method was called from a completion closure of a NSURLSession task in the subclass.

func showSuccessHUDwithMessage(msg: String) {
    dispatch_async(dispatch_get_main_queue()) {
        let successHud = MBProgressHUD(view: self.view)
        self.navigationController?.view.addSubview(successHud)

        successHud.mode = .CustomView
        successHud.customView = UIImageView(image: UIImage(named:"37x-Checkmark"))
        successHud.labelText = msg
        successHud.show(true)
        successHud.hide(true, afterDelay: 1.0)
    }
}

When I check the value of self in showSuccessHUDwithMessage: I still get the subclass, but wasn't able to get its navigationController

harinsa
  • 3,176
  • 5
  • 33
  • 53
  • Is your View Controller inside a NavigationViewController ? The navigationController property of a View Controller will return a valid navigation controller object only if the view controller is in a navigation controller's navigation stack – Kevin Machado Jul 06 '15 at 08:57
  • @thedjnivek it is, I checked before calling this method and the navigationController has a value. – harinsa Jul 06 '15 at 09:00

0 Answers0