Hello Andrew,

This was asked on stackoverflow [1] recently. The workaround is to
override only the default constructor and use the properties to set
all values.

Not sure (yet) about the root cause, it's on my TODO but I got other
bugs (without workarounds) to go thru before that.

Feel free to open a bug report (less chance that I forget about it ;-)
Sebastien

[1] http://stackoverflow.com/questions/7692522/subclassed-uialertview-not-shown

On Thu, Oct 20, 2011 at 5:07 PM, Andrew Young <andrewdyo...@gmail.com> wrote:
> App crashes when I try to inherit from UIAlertView. See stack trace and
> sample code below. MonoTouch 5.0.
> Any ideas? I have a sample app that shows this for anyone interested.
> public class ViewController : UIViewController
> {
>   private DateTimePickerView _pickerView;
>   public ViewController ()
>   {
>   }
>   public override void ViewDidLoad ()
>   {
>     base.ViewDidLoad ();
>     new NotReachableAlertView ().Show ();
>   }
> }
> public class NotReachableAlertView : UIAlertView
> {
>   public NotReachableAlertView() : base("Title", "Message", null, "Cancel")
>   {
>   }
> }
> Unhandled Exception: MonoTouch.Foundation.MonoTouchException: Objective-C
> exception thrown.  Name: NSInternalInconsistencyException Reason: Requesting
> the window of a view (<PickerViewCrash.NotReachableAlertView: 0x79a700;
> 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:.
>   at MonoTouch.UIKit.UIAlertView.Show () [0x00000] in <filename unknown>:0
>   at PickerViewCrash.ViewController.ViewDidLoad () [0x00006] in
> /Users/Andrew/Projects/PickerViewCrash/ViewController.cs:20
>   at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00000] in <filename
> unknown>:0
>   at PickerViewCrash.AppDelegate.FinishedLaunching
> (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary
> options) [0x00031] in
> /Users/Andrew/Projects/PickerViewCrash/AppDelegate.cs:32
>   at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String
> principalClassName, System.String delegateClassName) [0x00000] in <filename
> unknown>:0
>   at PickerViewCrash.Application.Main (System.String[] args) [0x00000] in
> /Users/Andrew/Projects/PickerViewCrash/Main.cs:16
> [ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.Foundation.MonoTouchException:
> Objective-C exception thrown.  Name: NSInternalInconsistencyException
> Reason: Requesting the window of a view
> (<PickerViewCrash.NotReachableAlertView: 0x79a700; 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:.
>   at MonoTouch.UIKit.UIAlertView.Show () [0x00000] in <filename unknown>:0
>   at PickerViewCrash.ViewController.ViewDidLoad () [0x00006] in
> /Users/Andrew/Projects/PickerViewCrash/ViewController.cs:20
>   at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00000] in <filename
> unknown>:0
>   at PickerViewCrash.AppDelegate.FinishedLaunching
> (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary
> options) [0x00031] in
> /Users/Andrew/Projects/PickerViewCrash/AppDelegate.cs:32
>   at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String
> principalClassName, System.String delegateClassName) [0x00000] in <filename
> unknown>:0
>   at PickerViewCrash.Application.Main (System.String[] args) [0x00000] in
> /Users/Andrew/Projects/PickerViewCrash/Main.cs:16
> Terminating runtime due to unhandled exception
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to