从 ViewController (storyboard) 调用 NavigationController (xib) [英] Call NavigationController (xib) from ViewController (storyboard)

查看:24
本文介绍了从 ViewController (storyboard) 调用 NavigationController (xib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常只为我的 iOS 使用故事板,但需要集成一个不使用故事板的 SDK,而是使用 xib.我的初始视图控制器来自故事板,当按下按钮 (IBAction) 时,我希望它转到 xib 视图控制器,但不确定如何以编程方式执行此操作.这是我的 AppDelegate:

I'm normally just use storyboard for my iOS, but needed to integrate an SDK which does not use storyboard, rather xib. My initial view controller is from storyboard, and when a button is pushed (IBAction), I would like it to go to the xib view controller, but not sure how programmatically to do so. Here is my AppDelegate:

 //AppDelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:...{   

// set to storyboard on launch
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard"
                                                         bundle: nil];

UIViewController* viewController = [mainStoryboard instantiateInitialViewController];
[self.window setRootViewController:viewController];

 [window makeKeyAndVisible];
 return YES;
 }

这是我的代码.h:

 //mainVC.h
 #import <UIKit/UIKit.h>

 @interface MainVC : UIViewController{
 UIWindow *window;
 UINavigationController *navigationController;
 }

 @property (nonatomic, retain) IBOutlet UIWindow *window;
 @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
 @property (nonatomic, retain) IBOutlet UIButton *buttonScan;

 -(IBAction) ActionScan;

 @end

还有.m:

 //mainVC.m
 @interface MainVC ()

 @end

 @implementation MainVC

 @synthesize window;
 @synthesize navigationController;
 @synthesize buttonScan;

 - (IBAction)ActionScan{

window.rootViewController = navigationController;
[window makeKeyAndVisible];

 }

推荐答案

initWithNibName 创建你的 xib viewController 实例

create instance of your xib viewController with initWithNibName

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

&然后将此控制器实例推送到导航控制器上

& then push this controller instance on navigation controller

[self.navigationController pushViewController:desController animated:YES]

这篇关于从 ViewController (storyboard) 调用 NavigationController (xib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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