iOS: Xcode: How do I switch a view upon launch

Posted on 2013-10-04
Medium Priority
Last Modified: 2013-10-19
I have an iOS application where I'm looking to see if a user has registered yet.  If the user has registered, I want the view to change from the main view to the homepage view upon launch.  Right now, I can't seem to figure out how to check which view is the firstResponder.  Any ideas?
Question by:pingeyeg
1 Comment
LVL 11

Accepted Solution

Deepak Lakkad earned 2000 total points
ID: 39549220

First of all you have to use your "HomePage" as main view (First Responder).

And In "didFinishLaunchingWithOptions", method check if user is not registered then show "Registration" screen.

Here are some code.

In didFinishLaunchingWithOptions method,

self.window.rootViewController = "Your HomePage"
[self.window makeKeyAndVisible];

if(some condition to check whether user is registered or not) {
        // If not Registered
        [self showRegistrationView];

Open in new window

Write a function to show Registration page as below:
- (void)showRegistrationView {
    UIViewController *topViewController = self.window.rootViewController;
    UIViewController *modalViewController = [topViewController modalViewController];
    if (![modalViewController isKindOfClass:[HomeViewController class]]) {
        HomeViewController* homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController"
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homeVC];
        [topViewController presentModalViewController:navController

Open in new window

The sample code is written from one of my Application.

You have to make correction for your need.

- Deepak Lakkad

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article I'm going to cover the basics and usages of NSInvocation. What is NSInvocation? Apple Developer Reference describes NSInvocation this way: An NSInvocation is an Objective-C message rendered static, that is, it is an action tur…
The Basics of Storyboard Storyboards were first introduced to developers in the release of iOS 5. They save the developer the trouble of designing each screen’s interface in a different file. The storyboard allows you to see the conceptual mockup o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question