未显示子类 UIAlertView

发布于 2024-12-08 21:06:54 字数 1592 浏览 0 评论 0原文

我正在对 UIAlertView 进行子类化。请参阅下面的代码。没什么特别的,只需在显示警报时设置一些布尔值,并在警报消失时重置它。但警报永远不会出现在屏幕上。屏幕变暗,仅此而已。我在应用程序输出中收到以下消息:

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

I'm subclassing UIAlertView. See code below. Nothing fancy, just set some bool if the alert is shown and reset it if it gets dismissed. But the alert never apepars on sreen. The screen gets dimmed and that's it. I get the following message in the app output:

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:.

What does this message want to tell me? I'm calling base. What more can I do?
Here's the class:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢蛋碎的人ぎ生 2024-12-15 21:06:54

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

希望这可以解锁你:-)

Not sure (I need to test that further) but the default constructor for your AlertView works (small text-less, button-less popup appear).

From that you can fake the whole thing with something like:

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

Hopefully that can unblock you :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文