iPhone Adding Sub View dynamically
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 MainViewC开发者_如何转开发ontroller 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
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.
精彩评论