Reputation: 5259
I have a view in which I am fetchind data from the web - calling a php script and get a JSON response. The way that I do it is by performing an NSUrlRequest.
The way I do it is like this:
-(void) viewDidLoad
{
.....
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:url]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"didReceiveResponse");
[self.responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"didFailWithError");
NSLog(@"Connection failed: %@", [error description]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]);
...
}
Now I have another UIView, that wants to be displayed when that screen opens - like a splash screen only for this screen (which is not the starting screen) - it would be a how to use it screen. I want to be visible only for 5 secs for example.
If I place the [self openCustomView]
inside the ViewDidLoad then I get a warning:
is not in the root view hierarchy
and the view does not open.
If I put in the connectionDidFinishLoading
then I am waiting for the data to download which can take time.
Is there a way to preview that splash screen and download the data in the background?
My openCustomView is this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
CustomView *vc = [sb instantiateViewControllerWithIdentifier:@"CustomViewID"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
Upvotes: 0
Views: 61
Reputation: 31016
This is a bit of guessing but, from the message, I suspect you're calling openCustomView
from the wrong spot. I don't believe self
(and its views) are considered part of the hierarchy during loading. I'd try viewDidAppear
.
Upvotes: 1