我通常只为我的 iOS 使用故事板,但需要集成一个不使用故事板的 SDK,而不是 xib。我的初始视图控制器来自情节提要,当按下按钮(IBAction)时,我希望它转到 xib 视图控制器,但不确定如何以编程方式执行此操作。这是我的 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
还有他们:
//mainVC.m
@interface MainVC ()
@end
@implementation MainVC
@synthesize window;
@synthesize navigationController;
@synthesize buttonScan;
- (IBAction)ActionScan{
window.rootViewController = navigationController;
[window makeKeyAndVisible];
}