Since this is the first controller/view that will be loaded, add a UIViewController in your MainWindow.xib document in Interface Builder, set its NIB name to the name of your XIB file (without the extension) and create and connect an outlet for it in the AppDelegate class.
Then, just add the view with to the window like you did, window.AddSubview(myViewControllerOutlet.View); without initializing the controller at all. It will be initialized by the runtime through the outlet. Dimitris Tavlikos Software Developer Email: [email protected] Twitter: http://twitter.com/#!/dtavlikos Blog: http://software.tavlikos.com On Jun 5, 2011, at 6:59 PM, savage wrote: > hi, > > i started a new iphone-testproject and added "iphone view with controller". > this view contains a simple button (outlet set). > > In my Main.cs I get that view with: > myview d = new myview(); > window.AddSubview(d.View); > window.MakeKeyAndVisible (); > > In the UIViewController i added: > public override void ViewDidLoad() { > base.ViewDidLoad(); > btn.TouchDown += delegate { > Console.WriteLine("test" + DateTime.Now.ToLongDateString()); > }; > } > > Everything works fine until I touch that button. Sometimes it works on first > time, but latestly on the second time I get that error: > Stacktrace: > > at (wrapper managed-to-native) > MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) > <IL 0x0009f, 0xffffffff> > at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] > in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26 > at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in > /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:31 > at dreck1.Application.Main (string[]) [0x00000] in > /Users/minimac/Projects/dreck1/dreck1/Main.cs:14 > at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object > (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff> > > > what did I wrong? > > -- > View this message in context: > http://monotouch.2284126.n4.nabble.com/iphone-view-with-controller-events-fail-tp3575227p3575227.html > Sent from the MonoTouch mailing list archive at Nabble.com. > _______________________________________________ > MonoTouch mailing list > [email protected] > http://lists.ximian.com/mailman/listinfo/monotouch _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
