Search code examples
c#iphoneinterface-builderxamarin.iosxib

iPhone, Monotouch, and XIB outlet issues


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.


Solution

  • 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?