views:

136

answers:

1

Newbie Q.

In my MainViewController, which is the first visible view.

I have a Circle class (no XIB) which subclasses UIView and overrides the draw method to draw a circle. Hello-World simple.

In the MainViewController how do I add the custom class I wrote so that it appears programatically?

Do I need to do anything besides overriding the draw method in Circle?

ian

+1  A: 

If you are not loading MainViewController's view property from the NIB file (it's not connected to anything in interface builder), then I believe that you want to override the loadView method in MainViewController with something like:

- (void)loadView {
    view = [[CircleView alloc] init];
}

This will get called automatically at the right time so when MainViewController is created, the view can be added to the window as a subview by whatever instantiates MainViewController.

Nimrod
MainViewController has it's own view, the new sub view I want to add on top.
BahaiResearch.com
In that case, in the viewDidLoad method of your controller: create the new subview then add it to the existing view with `[self.view addSubview:circleView]`
Nimrod