我没有使用情节提要或任何东西。我只是创建可可类并将它们单独链接起来。我可以加载默认的View Controller,即SplashViewController,但是我无法过去。
我有php,android编程和python的经验,但是我对Obj-C的工作方式以及iOS框架的工作方式一无所知:(
SplashViewController.m
-(void)initializeInterface
{
//Initialize start button
[self.startButton addTarget:self action:@selector(startActivity) forControlEvents:UIControlEventTouchDown];
//Initialize fading backgrounds
[self animateImages];
}
-(void)startActivity
{
PhoneViewController *phoneView = [[PhoneViewController alloc] initWithNibName:@"PhoneViewController" bundle:nil];
[self.navigationController pushViewController:phoneView animated:YES];
}
SplashViewController.h
#import <UIKit/UIKit.h>
#import "PhoneViewController.m"
@class PhoneViewController;
@interface SplashViewController : UIViewController
@property (strong, nonatomic) PhoneViewController * phoneViewController;
@property UIImage *splashbg1;
@property UIImage *splashbg2;
@property (nonatomic, retain) IBOutlet UIImageView *splashbg;
@property (nonatomic, retain) IBOutlet UIButton *startButton;
-(void)initializeInterface;
-(void)animateImages;
-(void)startActivity;
@end
编辑
classAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
//Move from delegate view controller to root view controller
self.window.rootViewController=[SplashViewController new];
[self.window makeKeyAndVisible];
return YES;
}
最佳答案
将初始视图控制器包装在导航控制器中。
否则,初始视图控制器的navigationController
属性为nil,而pushViewController
无效。
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: splashViewController];
关于ios - 如何启动没有 Storyboard 的另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37274814/