Several views in one window

I am writing a presentation based application, but I am a bit confused about loading my views. I would like to have four different views loaded simultaneously in one window. I can’t figure out how to do this. I would rather do everything programmatically, rather than using the interface constructor, if possible.

My 4 views: UIView, UIWebView, UITableView and another UIView with buttons.

Thanks in advance for your help.

+4
source share
2 answers

The views in the iPhone application are arranged hierarchically - that is, each view has a "parent" view (except for the root view). An interesting bit here is that UIWindow itself is a subclass of UIView, so you can add all four views to your window directly. (This may not be the best approach, but perhaps the easiest.)

All you really need to do is initialize each of the four views programmatically with the location and size that you want them to display in UIWindow. You do this by providing each view with a frame parameter, either in the init method or after (depending on the type of view). So, for example, in your application, you can add this code:

 CGRect frame = CGRectMake(0.0, 0.0, 100.0, 100.0); UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease]; [window addSubview:view]; 

This will create a 100x100 pixel view and add it to the upper left corner of the window. You can do similar things for each of the other three species.

Note that developers usually do not initialize views directly in the application delegate. A better approach would be for the fifth view to take its place as the root view for the other four, and then add that root view to the window. You can use the view controller for the fifth view to simplify this task - move the view initialization code to this view controller implementation, and then from the application delegate, you can simply instantiate the view controller and let it take over from there.

+5
source

You can use [self parentViewController] to access the parent UIView

0
source

All Articles