Problemas de salida de iPhone, Monotouch y XIB

I'm having a problem with mapping controls in a subview back to fields on the owning controller. Specifically, I have mapped outlets for each of my "controls" to File's Owner. Monotouch then generated code for the controller's xib designer.cs file to reference these controls as properties on the controller class. However, when I run my code; I get object is null errors when trying to set properties on the controls. Digging into the issue with the debugger; it appears GetNativeField is returning null when trying to access the outlets by their names from the xib file.

Anyone have any ideas why this would be happening? I've checked the .xib file, and the generated code; the Outlet, Property, and Field names are consistent with one another.

preguntado el 09 de enero de 11 a las 01:01

3 Respuestas

Note that the outlets will only be accessible after the view has been loaded and that happens in LoadView() or by accessing the UIViewController's "View" property (this will load the view implicitly). Only then the the IB content gets constructed and is available for use.

So if you want to change stuff, you would either manually call LoadView(), or override it in your view, call base.LoadView() and then access the outlets.

Respondido el 14 de enero de 11 a las 01:01

I figured out what was causing the issue; it was how I was pushing the controller on the stack:

using(var batteryController = new BatteryController()){

    navigationController.PushViewController(batteryController,true);

}

It seems that when dispose is called on the controller, the NIB resource is removed from memory; which was causing the issue.

However, this brings up another question. Aren't you supposed to call dispose on the new controller once it's been pushed onto the stack? In objective C, when you push a controller on the stack; your supposed to call release afterwards. So what am I doing wrong then?

contestado el 16 de mayo de 16 a las 00:05

well on MonoTouch there is a Garbage Collector that it will automatically release the non referenced resources in your application as mentioned on documentation -> Mono comes with a garbage collector that allows developers to focus on their software and let the runtime take care of the bookkeeping required to release objects. This avoids common memory leaks and reduces the amount of code that needs to be written to avoid these leaks. Source: monotouch.net/… - dalexsoto

you should add the outlets on the AppDelegate. give this a try also on my blog it's a video of a simple calculator, it's in spanish but if you watch it its very self explanatory you can watch it here http://alexsoto.me/calculadora-monotouch it should help you to get started :) hope this helps Good luck, if i can help you on anything else just let me know

Edit: also you can check this video this one uses subviews also should help you, this one its in english http://www.alexyork.net/blog/post/Selecting-a-contact-from-the-Address-Book-with-MonoTouch.aspx

contestado el 24 de mayo de 19 a las 19:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.