1

Many times I'll read Obj-C code and need the value to one of their constants present in one of the Obj-C header files.

For notifications, I've been able to find them in MonoTouch such as UIApplication.DidEnterBackgroundNotification.

Is there a standard way to get such values? I am needing to lookup UINavigationControllerHideShowBarDuration for an odd reason.

jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182

1 Answers1

2

UINavigationControllerHideShowBarDuration is a CGFloat, which MonoTouch maps to a .NET System.Single (float in C#).

You should be able to use MonoTouch.ObjCRuntime.Dlfcn.GetFloat method to retrieve the constant (it could change between versions and should not be embedded like a C# const) value at runtime. E.g.

IntPtr handle = Dlfcn.dlopen (Constants.UIKitLibrary, 0);
return Dlfcn.GetFloat (handle, "UINavigationControllerHideShowBarDuration");
poupou
  • 43,413
  • 6
  • 77
  • 174
  • I'll try it. Does `handle` need to be closed within a try-finally block? – jonathanpeppers Jan 09 '12 at 22:21
  • (a) In this case closing should not be an issue since the library is already loaded into memory. (b) `MonoTouch.Constants` is public - it's also very handy to know the version of MonoTouch at runtime :-) – poupou Jan 09 '12 at 22:34