Question

i have several controls (subclasses of UIView) placed on a UIScrollView. Now I want to remove them from the UISrollView and create new controls. The code below runs but has no effect! What am i doing wrong?

        for (int i = 0; i < myScroll.Subviews.Length; i++) {
            Console.WriteLine (myScroll.Subviews [i].GetType ());
            myScroll.Subviews [i].Dispose ();
            myScroll.Subviews [i] = null;
        }
Was it helpful?

Solution

Use RemoveFromSuperview():

foreach(View sub in myScroll.Subviews)
{
   sub.RemoveFromSuperview();
}

OTHER TIPS

You must remove your control/view only from super view:
If you have those hierarchy of controls

CustomControl <- UIView <- UIScrollView

You can find CustomControl (with help of method ViewWithTag(int tag)) inside of parents UIView or UIScrollView.
BUT: to remove CustomControlsuccessfully, you must call only:

UIView.ViewWithTag(tag).RemoveFromSuperView();

and next line of code will not remove your control:

UIScrollView.ViewWithTag(tag).RemoveFromSuperVew();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top