Show View Controller Modally on First Startup - iphone

I'd like to have a view with instructions on how to use my app show up on the first time the app is opened. I have handled the problem of the only showing this view on the first startup using NSUserDefaults, but I am having trouble getting the view to display the way I want it to modally, not as the rootViewController. Here is my AppDelegate.m code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
BOOL hasShownStartup = [[NSUserDefaults standardUserDefaults] boolForKey:kAppHasShownStartupScreen];
if (!hasShownStartup) {
[self showInstructions];
}
[self.window makeKeyAndVisible];
return YES;
}
- (void)showInstructions
{
NSLog(#"showing instructions");
InstructionsViewController *howToView = [[InstructionsViewController alloc] initWithNibName:#"InstructionsViewController"
bundle:nil];
self.instructionsViewController = howToView;
[howToView release];
UINavigationController *howtoNavController = [[UINavigationController alloc]
initWithRootViewController:self.instructionsViewController];
self.instructionsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.viewController presentModalViewController:howtoNavController animated:NO];
[howtoNavController release];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kAppHasShownStartupScreen];
}
I want my rootViewController to remain self.viewController. I want to be able to click 'Done' on the instructionsViewController nav bar to transition back to the rootViewController. Executing the code as written never shows the instructions view. The only way I can see instructionsViewController is if I change the line [self.viewController presentModalViewController:howtoNavController animated:NO]; to self.window.rootViewController = self.instructionsViewController; but this is obviously not what i want (unless I could modally transition back to viewController).
Hopefully I've made it clear enough what I am trying to accomplish. Thanks in advance.

Try moving [self showInstructions]; to applicationDidBecomeActive: instead.

Try putting the [self showInstructions] after [self.window makeKeyAndVisible]:
[self.window makeKeyAndVisible];
if (!hasShownStartup) {
[self showInstructions];
}

Related

Unable to present a modal view controller completely over the top of a tab bar controller

I'm creating a tabbed iPhone application. When the application launches, if the user is not logged in, a modal view is supposed to be presented over the top of the tab bar controller (so it looks like this is the first screen). Upon login the modal view slides away to reveal the tab bar controller behind it.
Unfortunately when I call [self.tabBarController presentViewController:self.loginViewController animated:NO completion:NULL] from inside my application delegate I can still see the tabs along the bottom of the screen. I need them covered.
Ironically when searching for a solution, I find most people are having the inverse problem.
I have noticed that if I don't set my window's rootViewController to the UITabBarController, only inserting its view as a subview of the window, then it works as expected, but Xcode complains about the lack of rootViewController. What's going on here?
My application delegate's -application:didFinishLaunchingWithOptions: method looks like this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self registerDefaults];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[
[self makeSellingListingsController],
[[[UIViewController alloc] init] autorelease], // stub
[[[UIViewController alloc] init] autorelease], // stub
[[[UIViewController alloc] init] autorelease] // stub
];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.tabBarController.view];
[self presentLogin]; // this doesn't cover the tabs, but it should
[self.window makeKeyAndVisible];
return YES;
}
- (void)presentLogin
{
[self.tabBarController presentViewController:[[[FLLoginViewController alloc]
initWithNibName:#"FLLoginViewController"
bundle:[NSBundle mainBundle]] autorelease]
animated:NO
completion:NULL];
}
Don't present it from the tab bar controller, but from the root controller in the first tab, in its viewDidAppear method. If you pass NO to the animation parameter, the modal screen will be the first thing you see when you start the app.

Splash screen with activity indicator works fine in iOS6 but not in iOS5

I would like to show a splash screen view with activity indicator to load some information from a server before entering inside my app. Below is how I do it:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FeedViewController *feedViewController = [[FeedViewController alloc] initWithNibName:#"FeedViewController" bundle:nil];
MenuViewController *menuViewController=[[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:feedViewController];
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:self.navController leftViewController:menuViewController rightViewController:nil];
deckController.panningMode=IIViewDeckNoPanning;
deckController.panningView=menuViewController.view;
self.window.rootViewController = deckController;
[self.window makeKeyAndVisible];
// show splash screen until data is loaded
SplashScreenViewController *controller = [[SplashScreenViewController alloc] initWithNibName:#"SplashScreenViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[feedViewController presentModalViewController:controller animated:NO];
return YES;
}
In FeedViewController.m, I did something like this:
- (void)viewDidLoad
{
// load data from a server
[self performSelector:#selector(dismissSplashScreen) withObject:nil afterDelay:0.0];
}
This code works very well with iOS6, but when I tested it with iOS5 the splash screen with activity indicator spinning just does not disappear. I suspect I might implement a splash screen in a wrong way. (But I don't understand why this works in iOS6?)
I solved this problem myself by using a bool variable to check whether the splash screen should be shown. The code for showing the splash screen is moved to viewDidLoad of FeedViewController instead.
This approach seems to work well for both iOS5 and iOS6.

App not navigating to second view

The code I am using
NSLog(#"before Navigate to second activity");
Signature *temp = [[Signature alloc]initWithNibName:#"Signature" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
NSLog(#"after Navigate to second activity");
On console,both the log statements are getting printed, but my app is not navigating me to the next View.Please correct me.
if you are not using a UINavigationController on your app you can not call pushViewController, use presentViewController:animated:completion: instead:
[self presentViewController:temp animated:YES completion:nil];
for more information check the documentation
The log messages would show anyway, so no surprise there. Add a callback to the delegate for that navigation controller (you must first set a delegate of course) for
navigationController:didShowViewController:animated:
There you can make sure that the viewController passed (make sure Signature is a ViewController instance).
i think your application is not with navigationController so in AppDelegate.m file assign rootViewController like this..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
RootViewController *viewController1 = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil] autorelease];
UINavigationController *navviewController=[[UINavigationController alloc]initWithRootViewController:viewController1];
self.window.rootViewController = navviewController;
[self.window makeKeyAndVisible];
return YES;
}
after that check its working..
CreditsViewController *viewController = [[CreditsViewController alloc] init];
[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];
you can try with above code

NavigationController not loading view

I'm using xCode 4.3.2 and started a blank application.
I have a navigation controller and a simple logincontroller. I want the login controller to be my root view so it is this first thing that a user does when they login.
I'm using the following code and when I run the application it displays a black screen. I put in logging in the LoginViewController.m->ViewDidLoad and it is being run is there something im doing wrong the LoginViewController.xib is very simple it just contains a button right now that will switch to a tab view controller once I figure this out.
Thanks in advance.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
UIViewController *loginController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyWindow];
return YES;
}
This is not right:
[self.window addSubview:navigationController.view];
change it to this:
self.window.rootViewController = navigationController;

Presenting Modal View Controller before window is visible

I would like to present a view controller modally before calling -makeKeyAndVisible on the application's window. However, this code only shows the mainNav view controller:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MainViewController *main = [[MainViewController alloc] init];
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:main];
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"Restore"])
{
DetailViewController *detail = [[DetailViewController alloc] init];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detail];
// changing main to mainNav does not help
[main presentModalViewController:learnNav animated:NO];
[detailNav release]; [detail release];
}
self.window.rootViewController = mainNav;
[main release]; [mainNav release];
[self.window makeKeyAndVisible];
return YES;
}
What am I missing?
You should better make the window appear and then present the modal view with animated=NO. What's the point of presenting the modal view before everything else is instantiated and displayed?
Edit
To try to make your code work, here are a couple of hints. Try this:
[mainNav presentModalViewController:learnNav animated:NO];
or this:
[main.navigationController presentModalViewController:learnNav animated:NO];
I'd say that these two methods work best if they're put after the makeKeyAndVisible call.