我正在尝试使用UINavigationController(Type navigationBarType, Type toolbarType)
构造函数来指定UINavigationBar
在 C# 中定义的自定义派生类。
但是,我的所有尝试都会导致 null ref 异常。我认为这与我的托管课程没有找到本机课程有关吗?
if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
rootNavController = new UINavigationController(typeof(UnderlayNavigationBar), null);
else
rootNavController = new UINavigationController();
而不是第二个空参数,传入默认值typeof(UIToolbar)
也无济于事。
System.NullReferenceException: Object reference not set to an instance of an object
at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject[NSObject] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x00037] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:365
at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass, MissingCtorResolution missingCtorResolution) [0x00013] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:348
at MonoTouch.ObjCRuntime.Runtime.GetNSObject (IntPtr ptr, MissingCtorResolution missingCtorResolution) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:430
at MonoTouch.ObjCRuntime.Runtime.TryGetOrConstructNSObjectWrapped (IntPtr ptr) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/Runtime.cs:658
at at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:TryGetOrConstructNSObjectWrapped (intptr)
at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend_IntPtr (intptr,intptr,intptr)
at MonoTouch.UIKit.UINavigationController.set_ViewControllers (MonoTouch.UIKit.UIViewController[] value) [0x00028] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UINavigationController.g.cs:345
如果有人对我使用此构造函数的原因感兴趣,我将移植本指南:http ://b2cloud.com.au/how-to-guides/custom-uinavigationbar-colors-in-ios7