ios - Check if a subview is in a view using Swift -


how test if subview has been added parent view? if hasn't been added, want add it. otherwise, want remove it.

you can use uiview method isdescendantofview:

if mysubview.isdescendantofview(someparentview) {     someparentview.mysubview.removefromsuperview() } else {     someparentview.addsubview(mysubview) } 

you may need surround if mysubview != nil depending on implementation.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -