Getting the view working in an App with no XIB
I've been trying to get a basic app working that doesnt use an XIB. It simply should load and draw a button.
开发者_StackOverflow中文版At the moment the screen just appears white with apparently nothing on it.
In my delegate I pass across to my viewController Class.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
return YES;
}
In my viewController class I implement loadview and viewDidLoad. Not sure if loadView is getting called. There is no XIB in this project.
-(void)viewDidload
{
[super viewDidLoad];
UIButton *singlePlayerButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]
retain];
singlePlayerButton.frame = CGRectMake(50.0, 30.0, 100.0, 30.0);
[singlePlayerButton setTitle:@"Test" forState:UIControlStateNormal];
singlePlayerButton.backgroundColor = [UIColor blueColor];
[singlePlayerButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal ];
[singlePlayerButton addTarget:self action:@selector(playAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:singlePlayerButton];
}
-(void)loadView
{
NSLog(@"loadView");
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
self.view = view;
[view release];
}
Is there something I am missing?
I though this would be really quiet simple but after 2hrs of hitting my head against the wall nothing has changed.
Thanks -Code
Your viewDidload
method has a case typo. It should be viewDidLoad
(capital L).
Stupid suggestion perhaps, but where in the app delegate are you instantiating viewController?
精彩评论