子类UIAlertView未显示

本文关键字:显示 UIAlertView 子类 | 更新日期: 2023-09-27 18:10:47

我正在子类化UIAlertView。参见下面的代码。没什么特别的,只要在警报显示时设置一些bool值,在警报被解除时重置它。但警告永远不会出现在屏幕上。屏幕变暗,仅此而已。我在应用程序输出中得到以下消息:

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

子类UIAlertView未显示

不确定(我需要进一步测试),但您的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);
    }
 ...

希望这能帮你解封:-)