开发者

iPhone Adding Sub View dynamically

开发者 https://www.devze.com 2022-12-16 21:43 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消