The difference between directly setting the view of the controller and adding a view as a preview

I just started learning objective-C and iphone sdk, and I have a question that I hope someone can help shed some light on.

What is the difference in the following:

self.view = someView;

and

[self.view addSubView: someView];

Say, for example, in a simple application where we have only one controller and one type of container (there are several image subzones). What is the difference between these two statements? The reason I ask is because I was looking for sample code, and I noticed that the view was initialized with images as a subtask:

if (self = [super initWithFrame:CGRectZero])
{
//adds some images as subviews here
}

As I understand it, initWithFrame: CGRectZero creates a frame the size of [0,0,0,0] (essentially invisible).

When I directly set the view with

self.view = someView;

, . , . : ? " " , - .

+3
3

, iPhone, .

, , Mail, . . [1] , . . , . . .., , .

- ; - . , . , , , .

. , , . . , (0,0), , , .

, self.view - , ; - ( ..). , self.view . ( : , . , bar, .) , , , . (, , , ):

someView.autoresizingMask = UIViewAutoresizingFlexibleWidth
                          | UIViewAutoresizingFlexibleHeight;

( Interface Builder - "".)

, someView . , , self.view:

someView.frame = CGRectMake(
                            0, // all the way to the left
                            0, // all the way at the top
                            self.view.frame.size.width, // same width as the root view
                            self.view.frame.size.height, // same height too
                           );

- subviews, , ? : , , . , , , , , , .

[1] , .

+9

, , .

self.view = view . ( , XIB) , .

[self.view addSubView: someView] , self.view . , someview nil, .

, self.view , - . - , self.view UIImageView UIWebView . subviews, , .

, , self.view , nil.

+1

Setting the "view" property of a view controller only changes the view it controls.

Adding a subtitle view of another view actually adds a subview under another view.

These are very different things, because each one sets up a view controller, and the other changes the view hierarchy.

As suggested, the reason you didn’t see anything was because the first way was the spy frame you were adding was CGRectZero (0).

0
source

Source: https://habr.com/ru/post/1704798/


All Articles