Reputation: 1060
Getting an error saying it could not load the nib in the bundle: NSBundle when my sub classed PageViewController attempts to load/display.
(See attached file screen shot)
I have tried deleting the viewcontrollers and associated code and recreating them again from scratch.
I have also completely shut down the iPhone simulator and Xamarin and restarted them in the hope it was an issue related to: Could not load NIB in bundle - inspiration needed but all to no avail.
Can anyone point out possibly where I am going wrong with this please?
Note: The OnboardingHome and OnboardingPAge ViewControllers where created within iOS Designer and sub classes created for each.
VC_OnboardingHome.cs
using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
namespace Performance
{
partial class VC_OnboardingHome : UIViewController
{
private UIPageViewController pageViewController;
private int pageCount = 3;
public VC_OnboardingHome (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
vc_onboardPage firstPage = new vc_onboardPage();
firstPage.PageIndex = 0;
pageViewController = new UIPageViewController (
UIPageViewControllerTransitionStyle.PageCurl,
UIPageViewControllerNavigationOrientation.Horizontal,
UIPageViewControllerSpineLocation.Min);
this.pageViewController.SetViewControllers (
new UIViewController[] { firstPage },
UIPageViewControllerNavigationDirection.Forward,
false,
s => {
}
);
this.pageViewController.GetNextViewController = this.GetNextViewController;
//this.pageViewController.GetNextViewController(this.pageViewController, this);
this.pageViewController.GetPreviousViewController = this.GetPreviousViewController;
//this.pageViewController.GetNextViewController(this.pageViewController, this);
this.pageViewController.View.Frame = this.View.Bounds;
//this.View.AddSubview(this.pageViewController.View);
this.View.AddSubview (pageViewController.View);
}
private UIViewController GetNextViewController(UIPageViewController pageController, UIViewController referenceViewController)
{
vc_onboardPage currentPageController = referenceViewController as vc_onboardPage;
if (currentPageController.PageIndex >= (this.pageCount - 1)){
return null;
}else{
int nextPageIndex = currentPageController.PageIndex + 1;
vc_onboardPage vc_onboardPage = new vc_onboardPage ();
vc_onboardPage.PageIndex = nextPageIndex;
return vc_onboardPage;
}
}
private UIViewController GetPreviousViewController(UIPageViewController pageController, UIViewController referenceViewController)
{
vc_onboardPage currentPageController = referenceViewController as vc_onboardPage;
if (currentPageController.PageIndex <= 0){
return null;
}else{
int previousPageIndex = currentPageController.PageIndex - 1;
vc_onboardPage vc_onboardPage = new vc_onboardPage ();
vc_onboardPage.PageIndex = previousPageIndex;
return vc_onboardPage;
}
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
}
}
vc_onboardPage.cs
using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
namespace Performance
{
partial class vc_onboardPage : UIViewController
{
private int pageIndex;
public int PageIndex
{
get;
set;
}
// public vc_onboardPage (IntPtr handle) : base (handle)
public vc_onboardPage () : base("vc_onboardPage", null)
{
Console.WriteLine ("Page -> _constructor");
// this.PageIndex = this.;
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
lbl_HeaderTxt.Text = "Label is here";
Console.WriteLine ("Page -> ViewDidLoad");
// Perform any additional setup after loading the view, typically from a nib.
// this.imgView.Image = UIImage.FromFile(string.Format("images/{0}.jpg", this.PageIndex + 1));
lbl_HeaderTxt.Text = string.Format("Page {0}", this.PageIndex + 1);
}
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
Console.WriteLine ("Page -> ViewDidAppear");
}
}
}
Stacktrace
2015-07-27 14:13:07.663 Performance[8146:1518846] Page -> _constructor
2015-07-27 14:13:11.291 Performance[8146:1518846] Unhandled managed exception:
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/johncogan/Library/Developer/CoreSimulator/Devices/116BF4AA-5D28-4B3A-91F2-B9FA4FBFDEE8/data/Containers/Bundle/Application/5BD82BA5-65EE-496F-8BCE-887FEC5522AD/Performance.app> (loaded)' with name 'vc_onboardPage' (Foundation.MonoTouchException)
at ObjCRuntime.Runtime.ThrowNSException (IntPtr ns_exception) [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/ObjCRuntime/Runtime.cs:167
at ObjCRuntime.Runtime.throw_ns_exception (IntPtr exc) [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/runtime/Delegates.generated.cs:100
at (wrapper native-to-managed) ObjCRuntime.Runtime:throw_ns_exception (intptr)
at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_int_bool_IntPtr (intptr,intptr,intptr,int,bool,intptr)
at UIKit.UIPageViewController.SetViewControllers (UIKit.UIViewController[] viewControllers, UIPageViewControllerNavigationDirection direction, Boolean animated, UIKit.UICompletionHandler completionHandler) [0x0005f] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/build/ios/native/UIKit/UIPageViewController.g.cs:148
at Performance.VC_OnboardingHome.ViewDidLoad () [0x00055] in /Users/johncogan/Development/xamarin/Performance_Shared/Performance/VC_OnboardingHome.cs:28
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIApplication.cs:63
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIApplication.cs:47
at Performance.Application.Main (System.String[] args) [0x00008] in /Users/johncogan/Development/xamarin/Performance_Shared/Performance/Main.cs:14
2015-07-27 14:13:11.292 Performance[8146:1518846] critical: Stacktrace:
Upvotes: 2
Views: 1433
Reputation: 2935
I assume you are using a storyboard and editing it in Xamarin's built-in iOS Designer.
How did you add your ViewControllers to your project? In my experience, one of the fail-safest ways to do so in Xamarin's iOS Designer is to just specify a class name in the properties of a View Controller.
This would generate a new VC-Class like this:
partial class vc_test : UIView
{
public vc_test (IntPtr handle) : base (handle)
{
}
}
Note that the constructor invokes the base constructor with an IntPtr as an argument. Contrast that with your constructor, which invokes it with a string argument:
// public vc_onboardPage (IntPtr handle) : base (handle)
public vc_onboardPage () : base("vc_onboardPage", null)
When I last checked, string arguments are only valid when using NIBs/XIBs, which are not used by iOS Designer. So I suspect this may be the source of your problem, as the string "vc_onboardPage" is also mentioned in your error message.
I'd try and do the following:
Feel free to comment.
Upvotes: 2