At the time of application:didFinishLaunchingWithOptions:
in Appdelegate, your app is ready to display the root controller, code-defined in that method itself or in IB if you’re using storyboard.
If you make the call to the webservice synchronously, within application:didFinishLaunchingWithOptions:
, your application will get stuck on the splash screen, but this is not a good practice, block the user interface.
So in your root controller, while waiting for the data to be returned from the service, do the following:
IN THE CODE:
#import "ViewController.h"
@interface ViewController ()
// crie uma propriedade para poder acessa-la no retorno dos dados do serviço.
@property (strong, nonatomic) UIView *splashScreenView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Cria a splash view
self.splashScreenView = [[UIView alloc] initWithFrame:self.view.bounds];
// define o background
self.splashScreenView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"splash-screen"]];
// cria o spinner
UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[loading startAnimating];
// adiciona o spinner na splash view
[self.splashScreenView addSubview:loading];
// posiciona o spinner no centro da splash view.
loading.center = self.splashScreenView.center;
// adiciona a splash view na view do controller
[self.view addSubview:self.splashScreenView];
}
- (void)meusDadosDoWebserviceRetornaAqui
{
// quando receber seus dados, remova a splash view da view do controller.
[self.splashScreenView removeFromSuperview];
}
Of course, you can do all this with a few milling machines, like an animation and such... Besides this View can also be done in IB, with a NIB file.
That’s up to you!
And the result is this below:
Yes this will help a lot!! I will be testing and already bring the result!! I had already come up with something like this, but I was having a hard time implementing it, your example code fell like a glove!!
– Tiago Amaral
your code works!! That’s good, but it doesn’t show up. Because what happens: The method that starts the download of the contents is in viewDidload of Viewcontroller. m So when the app starts running, it enters this method and only comes out when it finishes downloading everything. And it shows nothing on the screen, not even using the code you passed. The idea would be to divide this into two processes, the splash being the main thread, and the download in the background in another thread. @Rodrigo Salles
– Tiago Amaral