Forum Xamarin Xamarin.iOS

InvalidCastException when accessing NavigationBar from NavigationController

Hi!

Using this simple code:
var top = this.NavigationController.NavigationBar.Frame.Height + UIApplication.SharedApplication.StatusBarFrame.Size.Height;

I get this exception:
System.InvalidCastException: Cannot cast from source type to destination type.
at at (wrapper castclass) object:__castclass_with_cache (object,intptr,intptr)
at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject[UINavigationBar] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x00000] in :0
at MonoTouch.ObjCRuntime.Runtime.GetNSObject[UINavigationBar] (IntPtr ptr) [0x00000] in :0
at MonoTouch.UIKit.UINavigationController.get_NavigationBar () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/.pmcs-compat.UINavigationController.g.cs:392
at iCible.Scanner.Client.iOS.DeviceConfigController.ViewDidAppear (Boolean animated) [0x0000e] in /Users/vincent/Projects/iCible/iCible.Scanner/iCible.Scanner.Client.iOS/DeviceConfigController.cs:87
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIApplication.cs:38
at iCible.Scanner.Client.iOS.Application.Main (System.String[] args) [0x00008] in /Users/vincent/Projects/iCible/iCible.Scanner/iCible.Scanner.Client.iOS/Main.cs:17

Posts

  • HEATHALLENHEATHALLEN USMember

    Try this instead...

    float statusBarPlusNavBarHeight = UIApplication.SharedApplication.StatusBarFrame.Height + NavigationController.NavigationBar.Frame.Height;

Sign In or Register to comment.