presentViewController doesn't do anything - iphone

I have a method called:
- (NSDictionary *)requestCompleted:(ASIHTTPRequest *)request{
As you probably guessed, it starts when i get a request back from a web server.
My issue is that the next command runs, but doesn't do anything…
[self presentViewController:loadingPageVC animated:YES completion:nil];
I feel like I forgot to init something but I can't anything wrong.

try this
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:loadingPageVC animated:YES completion:nil];
});

Related

Dismiss MBProgressHUD when delegate method fires

First time working with a HUD and I'm confused.
I setup the HUD like this in my viewDidLoad:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[[[WSXmppUserManager shared] xmppStreamManager] connect];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
The HUD doesn't show. I think the reason is as follows. The xmpp connect method fires off a connection request to the xmpp server and then it's done. So there is no activity to wait for as is.
However, the connection isn't established until the server responds and the following delegate method is fired:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
I want to wait for this and only then dismiss the HUD, but I'm at a loss as to how to do that. I'm missing something very simple.
You need to move this code
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
After your long running method has finished... that is, if this code is indeed returning immediately
[[WSXmppUserManager shared] xmppStreamManager] connect];
The hud is likely never going to display... as it gets told to display and then told to hide on the same run loop or perhaps one run loop right afterwards...
Why not put it at the end of this method if this indicates that a response has been received and the operation is completed?
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
HUD =[[MBProgressHUD alloc] initWithWindow:self.view];
[HUD setDelegate:self];
[self.view addSubview:HUD];
[HUD showWhileExecuting:#selector(connectToServer)
onTarget:self
withObject:nil
animated:YES];
In the connectToServer
-(void)connectToServer
{
[[[WSXmppUserManager shared] xmppStreamManager] connect];
}
As soon as the connectToServer method comepletes it task in the background , a delegate of MBProgressHUD called hudWasHidden: is automatically called
-(void)hudWasHidden:(MBProgressHUD *)hud
{
//Further work after the background task completed
}

shadow screen occur with Social Framework on iOS

I create application with feature 'shared with facebook'
I use this code for make a facebook sharing
[facebookViewController setInitialText:[NSString stringWithFormat:#"via %#", self.randomGame.name]];
NSLog(#"%#", self.resultImageView.image);
[facebookViewController addImage:self.resultImageView.image];
[facebookViewController setCompletionHandler:^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Dialog Did Cancel");
}
}];
[self presentViewController:facebookViewController animated:YES completion:nil];
I already have allocation/initialization facebookViewController object with SLComposeViewController.
first time I share there is no problem.
But, I share second time I get a shadow screen like this
can anyone help ?
Thanks for advance.
i am not sure but every time you present the facebook popover you also need to dismiss it in the completion block like
[facebookViewController dismissViewControllerAnimated:YES completion:Nil];
hope it helps
I done it with code
facebookViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookViewController setInitialText:[NSString stringWithFormat:#"via %#", self.randomGame.name]];
[facebookViewController addImage:self.resultImageView.image];
[self presentViewController:facebookViewController animated:YES completion:nil];

iOS - dismissing a facebook window do not fires dismissViewController completion block

I have this code compiled and running for iOS 6.
SLComposeViewController *control = [SLComposeViewController composeViewControllerForServiceType:...];
[control setInitialText:...];
[control addURL:...];
[control setCompletionHandler:^(SLComposeViewControllerResult result) {
[self dismissViewControllerAnimated:YES completion:^{
// do something
}];
}];
[self presentViewController:control animated:YES completion:nil];
if this is used as a Twitter control, it works fine, but if it is used as a Facebook control, the completion block of the dismissViewController is not called, ever!!! (the doSomething part never runs).
I thought this could have something to do with the controller being dismissed not on the main thread, so I have changed that to
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:^{
// do stuff...
}];
});
without success.
Is this an iOS 6 bug? how do I solve that?
this is the solution:
[self dismissViewControllerAnimated:YES completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.6 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
// do stuff
});
this is probably an iOS 6 bug related to the dismissViewController API.
EDIT: I have created a more powerful solution and posted here

Showing MBProgressHUD during method duration

I have a method to get contacts from the address book and doing some stuff with them ("getContactInformation").
This process is a bit long (a few seconds) and after this process I show a new ViewController. To make it friendly to the user I would like to use MBProgressHUD to show an activity indicator at the beginning of the process and hide it at the end.
Which is the best way to do it? I've test this:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = #"Retrieving information...";
[self getContactInformation];
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self presentViewController:newController animated:NO completion:nil];
But it doesn't work (It doesn't show the indicator). Anyone can help me?
Thank you in advance
Keep a separate method for [self presentViewController:newController animated:NO completion:nil];. And try calling that method after some particular delay. That should be solving the problem.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[self getContactInformation];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.mapView animated:YES];
});
});
This will spawn a thread to run getContactInformation and won't block the main thread which is required to do UI changes (such as displaying the HUD).
I'm guessing the main thread is getting locked up when you get contact info and doesn't have time to update to show the HUD. Once the method is complete, it gets the main thread again to update the UI (removing the HUD).

Calling presentModalViewController just after dismissModalViewControllerAnimated has problems

I have the code
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
[menuViewController dismissModalViewControllerAnimated:YES];
[GameKitWrapper getSingleton].match = match;
match.delegate = [GameKitWrapper getSingleton].remotePlayer;
[menuViewController presentModalViewController:avatarSelectionViewController
animated:YES];
}
But I have the problem that the dismiss is working but not the present. When I changed dismissModalViewControllerAnimated:YES to dismissModalViewControllerAnimated:NO it worked but does not look nice.
Any help is appreciated.
#adam has the right idea, but you don't want to wait for some arbitrary delay. That's fragile because it might take any amount of time for the animation to complete. You want to wait for the previous view controller to actually finish dismissing. The best place in my experience to put this is in your current view controller's viewDidAppear:. That will be called after your modal has completely gone away. See this question for some example code addressing a similar problem.
Try waiting for a second....
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
[menuViewController dismissModalViewControllerAnimated:YES];
[GameKitWrapper getSingleton].match = match;
match.delegate = [GameKitWrapper getSingleton].remotePlayer;
[self performSelector:#selector(presentModal) withObject:nil afterDelay:1.0];
}
- (void)presentModal {
[menuViewController presentModalViewController:avatarSelectionViewController
animated:YES];
}
Try calling:
[menuViewController dismissModalViewControllerAnimated:NO];
before calling:
[menuViewController presentModalViewController:avatarSelectionViewController
animated:YES];