hitheredude
hitheredude

Reputation: 939

Load the view when app starts

I want to create a app with only one view(TestViewController.h TestViewController.m). (no Tabbar, no Navigation Bar) Don't know why after i launch the app, the screen is totally black. It seems that the app did not load the view successfully? Since if the view is loaded, the screen should be white. Am I right or not?

Here's AppDelegate.h

#import <UIKit/UIKit.h>
@class TestViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UIWindow *window;
    TestViewController *testrViewController;   
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TestViewController *testViewController;

@end

Here's AppDelegate.m

#import "AppDelegate.h"
#import "TestViewController.h"

@implementation AppDelegate

@synthesize window = window;
@synthesize testViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self.window addSubview:testViewController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

Upvotes: 0

Views: 110

Answers (3)

Sr.Richie
Sr.Richie

Reputation: 5740

It seems to me that you're not instatiating the class

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // add this line
 testViewController = [[TestViewController alloc] init];
 [.....]
 }

Hope it helps

Upvotes: 3

sandy
sandy

Reputation: 1948

did you create .xib for testViewController. If not then you have to add a subview over your testViewController. and then try. I hope it will work.

UIView *testView=[[UIView alloc]initwithFrame:CGRectMake(0,0,320,480)];

[testViewController addsubview:testView];
[self.window addSubview:testViewController.view];
[self.window makeKeyAndVisible];

Upvotes: 0

Shrey
Shrey

Reputation: 1977

if you are creating it programmatically, then you should also instantiate window

UIWindow *aWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = aWindow;
[aWindow release];

then your ViewController

testViewController = [[TestViewController alloc] init];

and then make it visible

[self.window addSubview:testViewController.view];
    [self.window makeKeyAndVisible];

Upvotes: 2

Related Questions