Search code examples
iosuiscrollviewxamarinsubviews

Remove UIView from UIScrollView in XAMARIN


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;
        }

Solution

  • Use RemoveFromSuperview():

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