I have been studying the iOS app structure, and almost got my head around the MVC paradigm, with the delegates, views and controllers. Then I came across an example on the net that comprised of just one AppDelegate file, with no views, view controllers, or nib files, and it works:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
CGRect bounds = self.window.bounds;
view = [[UIView alloc] initWithFrame: bounds];
[view setBackgroundColor: [UIColor yellowColor]];
[self.window addSubview: view];
CGRect labelFrame = CGRectMake(30, 30, 100, 30);
label = [[UILabel alloc] initWithFrame: labelFrame];
[label setText: @"My Label"];
[label setTextAlignment: NSTextAlignmentCenter];
[label setTextColor: [UIColor orangeColor]];
[view addSubview: label];
CGRect buttonFrame = CGRectMake(vCentre - 50, hCentre - 20, 100, 30);
button = [[UIButton alloc] initWithFrame: buttonFrame];
[button setTitle: @"My Button" forState: UIControlStateNormal];
[[button titleLabel] setTextAlignment: NSTextAlignmentCenter];
[button setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
[view addSubview: button];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents: UIControlEventTouchDown];
[self.window makeKeyAndVisible];
return YES;
}
How is this working without any view controller or root view controller set? Does this mean that view controllers aren't really required?