如何从Xamarin的UIView中删除孩子?

时间:2017-01-18 21:33:54

标签: xamarin xamarin.ios

我有这个......

public partial class ViewController : UIViewController
{
    UIView[] seqPages;
    ...
}

private void loadApp()
{
     int seqCount=5;
     for (int i = 0; i < seqCount; i++)
        {
            seqPages[i] = new UIView()
            {
                Frame = new CoreGraphics.CGRect(0, 0, vpWidth, vpHeight)
            };
            string s = app.sequence[i];
            var img = UIImage.FromFile("pages/myimg.png");
            UIImageView imgView = new UIImageView(new CoreGraphics.CGRect(0, 0, 1000, 1000));
            imgView.Image = img;
            imgView.ContentMode = UIViewContentMode.ScaleAspectFit;
            seqPages[i].Add(imgView);
            mainContainer.Add(seqPages[i]);
        }
}
private void removePage(index){
   //Remove the children of seqPages UIVIew array
}

所以,在注释“//删除seqPages UIVIew数组的子节点”我需要类似的东西:seqPages [index] .removeAllChildren();

我无法在Google上找到如何归档此内容。有谁能够帮我 ?

1 个答案:

答案 0 :(得分:2)

UIView有一个RemoveFromSuperview方法会将其从“父级”中删除:

foreach (var view in this.View.Subviews)
{
    view.RemoveFromSuperview();
}