[MonoTouch] MonoTouch + action handler + simulator issue

ChrisNTR chrisntr at gmail.com
Mon Dec 20 14:40:09 EST 2010


Your view controller is probably getting Garbage collected.

Change you Main.cs to look a little like this

                ViewController viewController;
                 // This method is invoked when the application has loaded
its UI and its ready to run
 public override bool FinishedLaunching (UIApplication app, NSDictionary
 viewController = new ViewController ();
window.AddSubview (viewController.View);
 window.MakeKeyAndVisible ();
 return true;



On 20 December 2010 19:18, Brian Long <brian at blong.com> wrote:

> Hello all
> I've bumped into an issue whilst getting the hang of MonoTouch.
> It is easily demonstrable with a simple app with 2 buttons, one of which
> responds (trivially, via an alert) to a delegate set up in code, one of
> which responds to an action set up in IB.
> The delegate one works perfectly.
> The action button always makes the app crash with a null reference
> exception on first run in the simulator.
> If you close the simulator and re-run, then the same will happen.
> However... if you simply back re-invoke the app in the same simulator
> session and press the same button again, it behaves as expected and
> displays the alert.
> The stack trace is useless (to my eyes) in pointing the finger at anything
> (nothing in my source is pointed at) and I wonder if this is known (I have
> failed to find a reference to it in searches thus far), where the fault
> lies, and if it is avoidable (without avoiding actions in IB).
> I attach the trivial C# app that gives the problem, and also the stack
> trace I get when the action button is hit.
> FYI, I currently have no iPhone so cannot see the comparative behaviour on
> a real device - would be interesting to be reassured that the device
> behaves appropriately all the time.
> Any feedback on the matter would be welcomed
> Thanks
> - Brian
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch

Microsoft ASPInsider
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20101220/3b4ab5ad/attachment.html 

More information about the MonoTouch mailing list