如何加载从当前视图控制器的实现文件的另一个视图控制器?(How do I load another

2019-08-17 16:32发布

I need to create an app wich features a login/singup form and then a custom Google Map. I am new to iOS programming and trying to learn the things needed for this app very fast.

So, I have created the frontend and the backend of the login form, it works. I have an action wich is triggered by the "Log in" button wich verifies the credentials and either trigger a error either presents the Google Map.

I want to show that Google Map in another view controller wich controls another xib file. I created the view controller and the xib file.

My question is how can I 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 it the "root view controller" of the window and maybe featuring a transition (considering my logic is ok :D) ?

Answer 1:

如果你想打开ViewController从另外一个,那么你应该在你的定义是这样的IBAction 。 这是好主意,做viewController财产虽然。

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]; 

}

你应该做的viewController作为rootViewController在你AppDelegate类是这样的

YourFirstViewController *firstViewController=[[YourFirstViewController alloc]initWithNibName:@"YourFirstViewController" bundle:nil];

self.window.rootViewController=yourFirstViewController;


文章来源: How do I load another view controller from the current view controller's implementation file?