How to load another view controller from the current controller implementation file?

I need to create an application that has a login / name form and then a custom Google map. I am new to iOS programming and very quickly learn the things necessary for this application.

So, I created the interface and backend of the login form, it works. I have an action that is triggered by the "Login" button, which checks the credentials and causes either an error or presents a Google map.

I want to show that Google Map is in a different view controller that manages another xib file. I created a view controller and xib file.

My question is: how to load another view controller from an action placed in the implementation file of the current view controller?

Now I have this code:

UIViewController *mapViewController = [[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController" bundle:nil]; 

How can I make this a “root view controller” in a window and possibly have a transition (given that my logic is fine: D)?

+8
ios objective-c iphone model-view-controller ios5
source share
1 answer

If you want to open the ViewController from another, you must define it like this in your IBAction . It is a good idea to create a ViewController as property.

FirstViewController.h

 @class SecondViewController; @interface FirstViewController : UIViewController @property(strong,nonatomic)SecondViewController *secondViewController; @end 

FirstViewController.m

 -(IBAction)buttonClicked:(id)sender{ self.secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; [self presentViewController:self.secondViewController animated:YES completion:nil]; } 

You should make viewController as rootViewController in your AppDelegate class something like this

 YourFirstViewController *firstViewController=[[YourFirstViewController alloc]initWithNibName:@"YourFirstViewController" bundle:nil]; self.window.rootViewController=yourFirstViewController; 
+17
source share

All Articles