Subclassed UIAlertView未显示

时间:2011-10-07 20:24:09

标签: c# .net ios xamarin.ios uialertview

我正在继承UIAlertView。见下面的代码。没有什么花哨的,只要在显示警报时设置一些bool,如果它被解除则重置它。但警报从未出现在屏幕上。屏幕变暗,就是这样。我在app输出中收到以下消息:

Requesting the window of a view (<TestApp.AlertView: 0xfad7160; baseClass = UIAlertView; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; layer = (null)>) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.

这条消息想告诉我什么?我打电话给基地。我还能做什么? 这是班级:

public sealed class AlertView : UIAlertView
    {
        public AlertView (string title, string message,UIAlertViewDelegate del, string cancelButtonTitle, params string[] otherButtons) : base(title, message, del, cancelButtonTitle, otherButtons)
        {
        }

        public AlertView() : base()
        {
        }

        public AlertView(NSCoder coder) : base(coder)
        {
        }

        public AlertView(IntPtr handle) : base(handle)
        {
        }


        public AlertView(NSObjectFlag t) : base(t)
        {
        }

        public override void Show ()
        {
            this.bIdleTimerWasRunning = AppDelegateBase.MainApplication.IsUIIdleTimerEnabled;
            AppDelegateBase.MainApplication.EnableUIIdleTimer(false);
            base.Show ();
        }

        private bool bIdleTimerWasRunning;

        public override void DismissWithClickedButtonIndex (int index, bool animated)
        {
            AppDelegateBase.MainApplication.EnableUIIdleTimer(this.bIdleTimerWasRunning);
            base.DismissWithClickedButtonIndex (index, animated);
        }
    }

1 个答案:

答案 0 :(得分:2)

不确定(我需要进一步测试),但AlertView的默认构造函数可以正常工作(显示无文字的小按钮,弹出按钮)。

从中可以伪造整个事情,例如:

public sealed class AlertView : UIAlertView
{
    public AlertView (string title, string message,UIAlertViewDelegate del, string cancelButtonTitle, params string[] otherButtons)
        : base ()
    {
        Title = title;
        Message = message;
        Delegate = del;
        // add buttons
        CancelButtonIndex = AddButton (cancelButtonTitle);
        foreach (string s in otherButtons)
            AddButton (s);
    }
 ...

希望能解锁你: - )