Xamarin.iOS:每次打开应用程序时,自定义视图都会多次出现

时间:2019-09-27 15:10:53

标签: xamarin xamarin.ios custom-controls custom-view

我有一个简单的自定义控件,其中包含单个元素UIPickerView。

[Register("CustomPicker")]
public class CustomPicker : UIView, IComponent
{
    public CustomPicker(IntPtr p) : base(p)
    {
    }

    public ISite Site { get; set; }

    public event EventHandler Disposed;

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);

        using (var g = UIGraphics.GetCurrentContext())
        {
            var label = new UIPickerView(new CGRect(rect.X, rect.Y, rect.Width, rect.Height));
            label.Model = new PeopleModel();
            AddSubview(label);
        }
    }
}

我有一个简单的故事板:

First time I open the app

然后,每当我让应用程序在后台运行(不终止)并再次打开时,我都会在现有应用程序的顶部放置一个供选择器使用,如下所示:

Second time I open the app

有什么主意我在这里做错了吗?当应用在后台运行时,是否有一种特定的方法可以“删除”视图?

0 个答案:

没有答案