Periodically every time after returning to the first controller by means of a button on the second controller

@IBAction func closeButton(sender: UIButton) { self.dismissViewControllerAnimated(false, completion: nil) } 

trying to press any button of the first controller, the application hangs and throws into an error box with an error. there is no error message when it is more beautiful in the logs. On the simulator and on the device, the application remains on, but it hangs, the buttons do not respond.

enter image description here For extra outlets checked, there is no excess. crash occurs after returning from only one controller. The same method is used on other controllers, but the crash never happened. What can be wrong?

  • Can I have a little more information? What is in the first controller, what is in the second? Doesn't write anything about the error? - VAndrJ
  • On the first controller, simply UIButton, by clicking on which, the transition to the second controller is performed via the Present Modally. On the second controller, too, just the UIButton, by clicking on which we return to the first screen, the action was described above. On the first screen there is a second button, by clicking on which we go to the third screen through Show. The application sometimes freezes when it’s just returned from the second screen, without having to press any more buttons, and it happens after returning when you press the button to go to the third screen. In the logs just does not write anything - Artur Skachkov
  • I will assume that the controller is unloaded from memory, and when I try to send something to the controller, a crash occurs. - Max Mikheyenko
  • Is this something you can fix? The example below did not help - Artur Skachkov

1 answer 1

Try adding this check:

 if([NSThread isMainThread]) { [self dismissViewControllerAnimated:YES completion:nil]; } else { [self performSelectorOnMainThread:@selector(closeButton:) withObject:nil waitUntilDone:YES]; } 
  • anyway the error remained - Artur Skachkov