hub
hub

Reputation: 164

Does removefromsuperview remove subviews?

If I have nested subviews, will all subviews get disposed if i call removefromsuperview?

Pseudocode:

UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(0 , 0, 100, 100)];
[self.view addSubview:viewA];
UIView *viewB = [[UIView alloc] initWithFrame:CGRectMake(25 , 25, 50, 50)];
[viewA addSubview:viewB];
UIButton *buttonC = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[viewB addSubview:buttonC];

And then buttonC is pressed:

[viewA removeFromSuperView];

All views are removed from the screen, but are they removed properly? Do I need to remove all views manually?

Upvotes: 2

Views: 2595

Answers (3)

Dren
Dren

Reputation: 2107

You can check it easy. Create subclass of uiview, overide it dealloc method and set brakepoint there. Than create instance of this class and add it to your view as subview. When you`ll call removeFromSuperview in your view brakepoint will be activated.

That`s it.

Upvotes: 1

iNevs
iNevs

Reputation: 99

As long as you have no other references to your views A..C, they will be removed and destroyed

Upvotes: 2

Wain
Wain

Reputation: 119031

All views will be removed. If you maintain a strong reference to viewA then all of the views will still be there and can be added again later. If you don't, they will all be destroyed.

Upvotes: 8

Related Questions