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.
我需要创建一个具有登录/单身形式然后是自定义Google地图的应用程序。我是iOS编程的新手,并且试图非常快速地学习这个应用程序所需的东西。
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.
我想在另一个视图控制器中显示Google Map控制另一个xib文件。我创建了视图控制器和xib文件。
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) ?
如何使它成为窗口的“根视图控制器”并且可能具有转换功能(考虑到我的逻辑是正确的:D)?
1 个解决方案
#1
17
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.
如果你想从另一个打开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];
}
You should make a viewController as rootViewController
in your AppDelegate
class something like this
您应该在AppDelegate类中将viewController设置为rootViewController,如下所示
YourFirstViewController *firstViewController=[[YourFirstViewController alloc]initWithNibName:@"YourFirstViewController" bundle:nil];
self.window.rootViewController=yourFirstViewController;
#1
17
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.
如果你想从另一个打开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];
}
You should make a viewController as rootViewController
in your AppDelegate
class something like this
您应该在AppDelegate类中将viewController设置为rootViewController,如下所示
YourFirstViewController *firstViewController=[[YourFirstViewController alloc]initWithNibName:@"YourFirstViewController" bundle:nil];
self.window.rootViewController=yourFirstViewController;