Search code examples
iosswiftstoryboardsegueuistoryboardsegue

Image and text field boarders doesn't load fast


I have a problem with a view controller that contains a login form and an image (UIImageView) created using a storyboard.

I have created a segue that transition from view 1 (initial View) to login screen. View 1 is the initial View Controller on viewDidAppear() of view 1 I have called the performSegueWithIdentifier that transition to the login View.

The transition works fine but the login view is shown before it is fully loaded, so the image in the login screen and the boarder of the login form are not shown when the view appears, after 10 to 20 sec, they appear (there is no code that is being run during this time).

And when i set the login View Controller as the initial View Controller, every thing is loaded fine with no problem. Do you have any idea on how i can fix this? did anyone experience this before?

i am using swift + xcode 6.1.1


Solution

  • I found a solution. The App checks on the server if the user is already logged in or not (function: isLoggedIn).

    If he is not logged in the performSegueWithIdentifier function is called to show the login View. The problem was that the my code calls performSegueWithIdentifier in a closure (success or failure callback) so it gets called before the isLoggedIn function finishes.

    So the segue gets called and the login view is displayed but somehow iOS judges that handling the connection is more important that displaying the logo image on the login view, that's why the logo gets displayed only after iOS finishes handling the connection.

    What i did to solve the problem is to call the isLoggedIn check in a new thread using CGD (Grand Central Dispatch) and called performSegueWithIdentifier in the mainQueue.