MonoTouch 5.2.13
I’m using a native ObjectiveC library via MonoTouch bindings. The library exposes a view controller. All is working fine, until I subclass the view controller. Then, I get NULL reference exceptions or part of the UI is not shown.
I have read about the problems with the btouch tool and the “-e” option. But from what I can see, the option is not present:
Tool /Developer/MonoTouch/usr/bin/btouch execution started with
arguments: /d:DEBUG ApiDefinition.cs /s:StructsAndEnums.cs
/tmpdir:obj/Debug/ios/ /sourceonly:obj/Debug/ios//sources.list
The subclass does (in this example) not add any functionality, but using it is enough to break the binding:
// Works.
var contr = new NativeController();
// Fails with various errors. Throws a NULL reference exception about some UIPopoverController being NULL, for instance.
public class SubclassedController : NativeController
{
public SubclassedController() : base()
{
}
}
var contr = new SubclassedController();
I figured out that adding the [NullAllowed] to a property solved the NULL reference exception.
The native controller exposes a property (nonatomic, strong) UIPopoverController *popoverController. This was bound as UIPopoverController PopoveController {get; set;} – adding the NullAllowed here solved the issue.
But now I’m facing issues with images not showing up and there is no obvious exception.
I assume these problems also derive from the fact that something is NULL when using the subclassed version but the native code seems to react on the NULL and handles it gracefully.
This leads to three questions:
- Why is the behavior different when using subclassing? What is MonoTouch doing to make this happen? Why do I get a NULL ref in the case I use a derived class? I’m not touching the UIPopoverController an either case.
- How can I find out what is wrong and how to fix it if there is no error?
- What else has to be taken care of, besides the NullAllowed?
This specific issue turned out to be two things:
NullAllowedattribute for aUIPopoverControllerEverything is working as expected with MonoTouch 5.3.6