iphone - 如何从当前 View Controller 的实现文件加载另一个 View Controller ?

标签 iphone ios objective-c model-view-controller ios5

我需要创建一个具有登录/注册表单和自定义 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/

相关文章:

iphone - 如何防止UItable View 的tableHeaderView滚动,粘在顶部

ios - 错误 ITMS-90642 : "Missing Info.plist Key. Your app' s info. plist 必须包含 'MSMessagesExtensionStoreIconName' key 。”

ios - 非常奇怪的 NSInvalidArgumentException 与 addSubview FBLoginView

ios - 如果我显示 destinationViewController,自定义 Fade Segue 不会设置动画

ios - 排除在 Assets 中使用 1x 的设备

ios - 删除嵌套的 UINavigationController 时 UINavigationBars 不显示

objective-c - pathForResource 返回 null

ios - google chromecast iOS SDK 是否支持锁屏控件?

iphone - 测试应用内购买时要使用哪个配置文件?

iphone - UIKitBackgroundCompletionTask - iPhone 应用程序崩溃