I have a UITabBarcontroller
in my app, and when the first tap is displayed, I launch a tutorial using MyBlurIntroductionView
To be simple, when the tutorial has been set up, I simply add it at the fullscreen of the app using :
[appDelegate.window addSubview:introductionView];
During this tutorial, I want to offer the ability to share via Twitter using this piece of code:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"Tweeting from my own app! :)"];
[parentController setModalPresentationStyle:UIModalPresentationFullScreen];
[parentController presentViewController:tweetSheet animated:NO completion:nil];
}else{
NSLog(@"Not available");
}
This code is thus called from the tutorial which is an UIView
, and parentController
is obtained thanks to this code:
UITabBarController *tabbarController =(UITabBarController*)self.window.rootViewController;
UIViewController *parentController = tabbarController.viewControllers[0]
The problem is that the share box is displayed UNDER the tutorial (when the tutorial is hidden, we can see the share box), and I would like to have it OVER the tutorial.
I guess this is because the tutorial is added as subview of the window, but I don't know how to do differently.
Do you have a few tips to solve this problem?
from what I can see, we got a problem with some architectural stuff ... Speak MVC.
Normally you attach some kind of RootViewController to your UIWindow. Everything else goes from there. Using your UIWindow leads to problem all over the place.
In your RootViewController you can check in viewDidLoad if this is the first time you open the app. If so create a TutorialViewController with the view you want to display and present the tutorialViewController. Either by pushing your tutorialViewController, if your RootViewController is in a UINavigationController.
[self.navigationController pushViewController:TutorialViewController animated: NO];
or by presenting it modally. But since you want to present TwitterViewController modally as well, this might be a bad idea. At least back in the days iOS had problems with presenting a viewController that was presented modally from one that were presented modally :)
[self presentViewController:TutorialViewController animated:YES completion:NULL];
In tutorialViewController you create your tutorialView - either with a xib, storyboard, - (void)loadView - and set up the Target/Action to fire against your TutorialViewController. ViewControllers are normally the place here you handle UI stuff (also UserInteraction). Don't do that in your views - Especially when checking for Twitter dependencies.
That way you have everything hierarchical and no implicit stuff in your project, which other developers would love to punch you fore. Please don't do something like this evar again ;)
UITabBarController *tabbarController =(UITabBarController*)self.window.rootViewController;
UIViewController *parentController = tabbarController.viewControllers[0]
Your actually problem right now: Your parentViewController is below your TutorialView. If your parentViewController presents something modally, it adds the modally presented view to its viewStack, which is still below your tutorialView. But as I said, clean MVC architecture will prevent running into those issues.