我需要创建一个具有登录/注册表单和自定义 Google map 功能的应用程序。我是 iOS 编程的新手,正在努力快速学习此应用所需的知识。
所以,我已经创建了登录表单的前端和后端,它可以正常工作。我有一个由“登录”按钮触发的操作,该按钮验证凭据并触发错误或显示 Google map 。
我想在另一个控制另一个 xib 文件的 View Controller 中显示 Google map 。我创建了 View Controller 和 xib 文件。
我的问题是如何从当前 View Controller 的实现文件中放置的操作加载另一个 View Controller ?
现在,我有这段代码:
UIViewController *mapViewController =
[[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController"
bundle:nil];
我怎样才能使它成为窗口的“ Root View Controller ”并可能具有转换功能(考虑到我的逻辑没问题)?
最佳答案
如果你想从另一个打开 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];
}
你应该在你的 AppDelegate
类中创建一个 viewController 作为 rootViewController
像这样
YourFirstViewController *firstViewController=[[YourFirstViewController alloc]initWithNibName:@"YourFirstViewController" bundle:nil];
self.window.rootViewController=yourFirstViewController;
关于iphone - 如何从当前 View Controller 的实现文件加载另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15464025/