如何从当前视图控制器的实现文件加载另一个视图控制器? [英] How do I load another view controller from the current view controller's implementation file?

查看:145
本文介绍了如何从当前视图控制器的实现文件加载另一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个具有登录/单身形式然后是自定义Google地图的应用程序。我是iOS编程的新手,并且试图非常快地学习这个应用程序所需的东西。



所以,我创建了登录表单的前端和后端,它作品。我有一个由登录按钮触发的动作,它会验证凭据并触发错误或显示Google地图。



我想要显示Google映射在另一个视图控制器中,控制另一个xib文件。我创建了视图控制器和xib文件。



我的问题是如何从当前视图控制器的实现文件中放置的操作加载另一个视图控制器? / p>

现在,我有这段代码:

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

如何使其成为窗口的根视图控制器并可能具有转换功能(考虑我的逻辑没问题:D)?

解决方案

如果你想打开 ViewController 来自另一个,那么你应该在你的 IBAction 中定义它。最好将 viewController 作为属性。



FirstViewController.h

  @class SecondViewController; 

@interface FirstViewController:UIViewController

@property(强,非原子)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设为您的 AppDelegate 类中的rootViewController 类似于此

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

self.window.rootViewController = yourFirstViewController;


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) ?

解决方案

If you want to open the ViewController from another one then you should define it like this in your IBAction. It is good idea to make the viewController as property though.

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 a viewController as rootViewController in your AppDelegate class something like this

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

self.window.rootViewController=yourFirstViewController;

这篇关于如何从当前视图控制器的实现文件加载另一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆