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!

2

There are 2 answers

0
Magicbjørn On BEST ANSWER

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!

0
husham1414 On

It is 2023 and this problem still appease for xamarion.IOS and working fine for xamarion.Android

I'm using the last xamarin forms version 5.0.0.2545

this answer solves my problem

I put a lot of codes after InitializeComponent();

to solve the problem just put MainPage = new MainPage(); directly after InitializeComponent(); in your App.xaml.cs

public App()
    {
        InitializeComponent();

        MainPage = new NavigationPage(new MainPage());
    }

The problem now it will directly go to the page without reading the other codes so to solve this move your code to another page,empty page or splash screen page and put your code in it like

public App()
    {
        InitializeComponent();

        MainPage = new NavigationPage(new MySplashScreenPage());
    }