Search code examples
iosobjective-cuiviewcontrolleruinavigationcontrollerpresentviewcontroller

How do I start another view controller with no storyboard?


I'm not using a storyboard or anything. I'm just creating the cocoa classes and linking them up individually. I can get to load up the default View Controller which is SplashViewController but i can't get past there.

I have experience in php, android programming and python, but i'm totally clueless on how Obj-C and how the iOS framework works :(

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

EDIT

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;
}

Solution

  • Wrap your splash view controller in a navigation controller.

    Otherwise, the navigationController property of your splash view controller is nil and pushViewController has no effect.

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: splashViewController];