MonoTouch.Foundation.MonoTouchException has been t

2019-07-05 13:04发布

问题:

I seem to be getting this issue whenever I run my iOS app within Xamarin.

MonoTouch.Foundation.MonoTouchException has been thrown

Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: ’NSBundle ... (loaded)' with name ‘RouteMeViewController'

I am trying to replace a GoogleMapsViewController with a RouteMeViewController using the Objective C library and Binder in an app that I was given to work on. My AppDelegate looks like this:

namespace ExampleApp.iOS
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{

    UIWindow window;
    RouteMeViewController viewController;

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);

        viewController = new RouteMeViewController ();
        window.RootViewController = viewController;
        window.MakeKeyAndVisible ();

        return true;
    }

}

RouteMeViewController

namespace ExampleApp.iOS
{
public partial class RouteMeViewController : UIViewController
{

    RMMapView MapView { get; set; }

    public RouteMeViewController () : base ("RouteMeViewController", null)
    {
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        MapView = new RMMapView(View.Frame, new RMOpenStreetMapSource().Handle);
        MapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;

        if (UIScreen.MainScreen.Scale > 1.0)
            MapView.AdjustTilesForRetinaDisplay = true;

        Add (MapView);
    }

}

}

Any help or direction is much appreciated, thank you!

回答1:

It seems you're missing a designer file in the resources of your solution. Even if you programmatically create controls and views, you need a designer file where they need to be drawn in, even if it's just an empty designer file. For IOS, you can use XCode for that. You can create files with the .xib extension. They will be compiled on your device, and the resulting file has the extension .nib. Make sure the target of the .xib file is the correct viewController of your project, else you'll still get the error.

I hope this helps. Good luck!