从XAMARIN中的UIScrollView中删除UIView

Kla*_*che 3 uiscrollview ios subviews xamarin

我有几个控件(UIView的子类)放在UIScrollView上.现在我想从UISrollView中删除它们并创建新的控件.下面的代码运行但没有效果!我究竟做错了什么?

        for (int i = 0; i < myScroll.Subviews.Length; i++) {
            Console.WriteLine (myScroll.Subviews [i].GetType ());
            myScroll.Subviews [i].Dispose ();
            myScroll.Subviews [i] = null;
        }
Run Code Online (Sandbox Code Playgroud)

Jas*_*son 11

使用RemoveFromSuperview():

foreach(View sub in myScroll.Subviews)
{
   sub.RemoveFromSuperview();
}
Run Code Online (Sandbox Code Playgroud)