Pages

Thursday, January 31, 2013

Add Multiple Screens with Slide Effect in xCode + UINavigation

Follow the Steps below for this.

Step 1. Create New Application then Empty Application
 - It will create applicationname.h and applicationname.m file inside your project

Step 2. Create New File> Cocoa Touch> Objective-C Class 
 - It will create newFileName.xib file with oits class Files (.h and .m)

Step 3. Take Subclass of UIViewController for this
 - Click the checkbox of "With XIB for user interface" - Lets Suppose Its Name is LoginViewController

Step 4. Create or Drop a Button inside xib file to load the next View

Step 5. Now go to AppDelegate.h file and add

@property (strong, nonatomic) UINavigationController *navigation;

Step 6. Now go to AppDelegate.m file and add Code 
 - Import your xib file class in AppDelegate.m file

#import "LoginViewController.h"

 - Then add the following code as mentioned in below function 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    //********************* Add the Following Code *********************//
    LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    self.navigation = [[UINavigationController alloc] initWithRootViewController:loginView];
    //[self.window addSubview:self.navigation.view]; // This is for Non Rotation
    [self.window setRootViewController:self.navigation]; // This is proper way to make the orientation as well
    //********************* Up to Here Code *********************//

    [self.window makeKeyAndVisible];
    return YES;
}

Step 7. If you want to hide the default Navigation by xCode then go to LoginViewController.m

and add following line in -(void)viewDidLoad

[self.navigationController setNavigationBarHidden:YES animated:YES];

Step 8. Now Create a new Obejctive C Class from Cocoa Touch and Give any name ( i have taken name as - TabsViewController

Step 9. Now go again to LoginViewControll.m (First Class File)
 - Import the Second Class you have made in this
#import "TabsViewController.h"

 - Now Made a function in LoginViewControll.m as below.

// This is basically a button Action function, which is declared in LoginViewController.h file. You can See many samples in google to make this linking


- (IBAction)loginContinueAction:(id)sender {
    TabsViewController *tabs = [[TabsViewController alloc] init];
    [self.navigationController pushViewController:tabs animated:YES];
}

So Here You are, You have New View after clicking the button :)

Just do the same steps from Step 8 to create new Views one after another.




If you are Working for sdk 4.6 and siulator 6.1 then you must need to work with storyboard. Easy to use and easy to handle.

For StoryBoard: http://varunxcode.blogspot.in/2013/09/appear-and-disappear-multiple-view.html

Reference: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/UsingViewControllersinYourApplication/UsingViewControllersinYourApplication.html

No comments:

Post a Comment