c# - 未显示子类 UIAlertView

标签 c# .net ios xamarin.ios uialertview

我正在子类化 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:.

这条消息想告诉我什么?我调用基地。我还能做什么? 这是类(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);
        }
    }

最佳答案

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

希望这可以解除你的封锁:-)

关于c# - 未显示子类 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7692522/

相关文章:

c# - 临时更改属性

ios - 设置在 MMDrawerController 中选择的默认项目

iphone - 如何在矩形中填充一条线

ios - 应用内购买 : request products randomly get some valid product and some invalid products?

c# - 如何处理跨应用域数据交换

c# - 具有 2 个外键 Entity Framework 的表

c# - 如何判断一个点是在线的右侧还是左侧

c# - 线程安全问题

java - 哪个开源 java 或 .net 项目具有最佳的单元测试覆盖率?

c# - 访问从java到dotnet的请求