IPHONE: check if there is a view in view mode

I'm going to do

[vistaX removeFromSuperview];

How can I check if vistaX is present in a super view before removing it? Deleting a view that is not there will cause the application to crash ...

Thanks for any help.

+3
source share
2 answers

You can protect it with:

if(vistaX.superview)
     [vistaX removeFromSuperview];

Although, I did not know that removeFromSuperview would fail if there was no supervisor. Are you sure this is a problem, and it may not be due to removeFromSuperview freeing up the view?

: , , vistaX count count 0 . , , , vistaX (.. "@property ()" ), , .

EDIT EDIT: ? , vistaX. IB.

+14

, ,

if(vistaX.superview!=nil)
   [vistaX removeFromSuperview];

, , -, .

+2

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


All Articles