developer
developer

Reputation: 5478

How to move between different views in iPhone

I have a Login view in my iPhone app. If the user successfully authenticates I want to move him from LoginViewController screen to MyViewController screen. Below is my code,

if([serverOutput isEqualToString:@"Yes"]){
        NSLog(@"Authentication correct");

        if(self.myviewController==nil)
        {
            MyViewController *myController=
            [[MyViewController alloc]initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];
            self.myviewController=myController;
            [myController release];
        }
}

But somehow the app doesnt do anything when i click on the Login button even though the authentication is correct. As i am new to iphone app development can anybody please help me out with the code..

Upvotes: 0

Views: 5680

Answers (2)

hoha
hoha

Reputation: 4428

Use UINavigationController .

Upvotes: 1

Convolution
Convolution

Reputation: 2351

To transition between views you're going to want to read up on UINavigationControllers. A UINavigationController is an object that manages a hierarchy of views. The UINavigationController is like a road map for going from one view to another in your applications flow and it achieves it's most basic features by calling the methods pushViewController:animated (to transition to a new view controller) and popViewController:animated (to transition back to the preview view).

In the case of your project you'd want to do the following.

  • Allocate and initialize a UINavigationController (in your application delegate if you plan on the login screen to be where your program starts) and assign it's root view to your login view controller.
  • If the user has been successfully authenticated, you would then construct an instance of the UIViewController you want to transition to and then instruct the UINavigationController to push this next view controller onto the navigation stack by calling pushViewController:animated:
  • At this point lets say you want the user to log out and return to the login screen once again, you can call this method popViewController:animated.

Here's the class reference for UINavigationController to get you started. It's got some great pictures explaining it's structure.

Upvotes: 6

Related Questions