Reputation: 11900
I'm fairly new iOS development. I have multiple viewController
s for my app, for example -
Each of these screens has its own viewController
.
What's the best way to transition between any two arbitrary viewController
s with an animation?
My current approach is -
viewController
in AppDelegate.m
This is both cumbersome and seems pretty inefficient, plus I'm not quite sure how to incorprate animated transitions here.
I see some examples with UINavigationController
, but it seems like that operates as a "stack" of views that you can go into and then back out of. I'm not looking to keep a history here, just switch from any view to another.
Any good ways to accomplish this?
Thanks!
Upvotes: 0
Views: 133
Reputation: 13343
As a beginner I believe the easiest solution for you it to use a Storyboard
and create a segue between your View Controller.
Inside your ViewController you should override prepareForSegue:
method to pass data to the segue.destinationViewController
Upvotes: 0
Reputation: 1878
Try this Code.
AppDelegate.h
#import <UIKit/UIKit.h>
#import "LoginViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) UINavigationController *navigationController;
@property (strong,nonatomic) LoginViewController *loginVC;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "LoginViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.loginVC = [[LoginViewController alloc]initWithNibName:nil bundle:nil];
self.loginVC.title = @"Login Page";
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.loginVC];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
}
LoginViewController.h
#import <UIKit/UIKit.h>
#import "MyProfileViewController.h"
@interface LoginViewController : UIViewController
@property (strong,nonatomic)MyProfileViewController *myProfileVC;
@end
Login button action in LoginViewController.m file
- (IBAction)pushMyProfileView:(id)sender
{
self.myProfileVC = [[MyProfileViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:self.myProfileVC animated:YES];
}
Upvotes: 2
Reputation: 26385
Basically you can achieve that by using:
Containment API is probably what you are looking for, you create a UIViewController that is responsible to manage the presentation of its child view controllers. Here is Apple Documentation, there are plenty of examples inside.
Upvotes: 0