just_just_just
just_just_just

Reputation: 43

myview = nil but there are still a view on superview

i put on a view named myView on superview, after that, i code myView = nil, but not remove from superview, and there are still a view like myView appeared in superview, please help me and tell me why.

Upvotes: 2

Views: 455

Answers (2)

CZ54
CZ54

Reputation: 5588

Your question is why myView = nil doesn't remove the view from superview ( and so, why it doesn't deallocate it ).

This is quite simple, when you do viewA addSubview:viewB you create a reference from viewA to viewB.

So when you do viewB = nil, you still have a pointer from viewA to viewB so ARC doesn't release the view.

That's why you should call [viewB removeFromSuperview] to delete the pointer.

Upvotes: 4

Pratik Jamariya
Pratik Jamariya

Reputation: 820

Please remove your view from super view before making it nil using [myView removeFromSuperView];

Upvotes: 0

Related Questions