I am new to objC and MVC. Need help with some basic stuff.
I am trying to create a redball programmatically using the view controller and UIImageView. My view controller is also created programmatically and so is the view. The ball does not appear (let alone animate it later) however I try on the simulator. Any help appreciated. What am i doing wrong? Here is my code snippet …
my app delegate.h:
>
@class HKViewController;
@interface HKAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
HKViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) HKViewController *viewController;
—————————-
my appdelegate.m: (not showing the dealloc methods)
@implementation HKAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
viewController = [HKViewController alloc];
self.viewController = viewController;
[window addSubview:viewController.view]; // is this required?
[window makeKeyAndVisible];
}
———————-
my view controller without nib file i.e. programmatically drawing the ball (but it doesn't show up

in the first place …. let alone animate it later … what am i doing wrong
my view controller.h:
#import <UIKit/UIKit.h>
@interface HKViewController : UIViewController {
CGPoint pos;
UIImageView *redBallView;
}
@property(nonatomic,retain) UIImageView *redBallView;
@end
my view controller.m: (not showing memory warning and dealloc methods)
#import “HKViewController.h”
@implementation HKViewController
@synthesize redBallView;
<p>
-(void) onTimer {
pos = CGPointMake(160,300);
redBallView.center =CGPointMake(redBallView.center.x+pos.x,redBallView.center.y+pos.y);
if(redBallView.center.x > 320 || redBallView.center.x < 0)
pos.x = -pos.x;
if(redBallView.center.y > 320 || redBallView.center.y < 0)
pos.y = -pos.y;
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
// Drawing code
UIGraphicsBeginImageContext(CGSizeMake(320,420));
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginPath(ctx);
CGContextAddArc(ctx,160,400,10,0,2*M_PI,1);
CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
CGContextFillPath(ctx);
UIImage *redBall = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
redBallView = [[UIImageView alloc] initWithImage:redBall];
redBallView.center = CGPointMake(160,300);
self.view = redBallView;
[self.view addSubview:redBallView];
//[self.view setNeedsDisplay];
[redBallView release];
pos = CGPointMake(14.0,7.0);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}