I have the following code:
[self.view bringSubviewToFront:loggingIn];
[self loginWithUsername:user Password:pw];
This is inside an IBAction method for a button press. The button stays highlighted until the user is logged in (this could take several seconds) and THEN the view appears. How come the view isn’t appearing before the login method is called?
John’s answer would work, but it has to do with the Run Loop than blocking threads. Basically, whenever your app receives an event such as a button getting clicked, your handler gets run in the main thread. Any changes you make to the UI happen after your handler finishes. This lets Cocoa optimize the graphics updates by analyzing/performing them together.
So you need to let your handler code finish in order to let the system start updating the UI – before invoking your loginWithUsername:Password: [sic] method. Scheduling a timer will bump it to the next iteration of the run loop (the timer going off becomes the “event” that triggers the next loop). So,
So do something like this:
It doesn’t have to be an array. You could also pack your username and password in a dictionary and use that as your argument instead.