收到错误,说它无法加载包中的nib:当我的子类PageViewController尝试加载/显示时,NSBundle。
(参见随附文件截图)
我尝试删除viewcontrollers和相关代码,然后从头开始重新创建它们。
我还完全关闭了iPhone模拟器和Xamarin并重新启动它们,希望这是一个与Could not load NIB in bundle - inspiration needed相关的问题,但都无济于事。
有人可以指出我可能在哪里出错吗?
注意:在iOS Designer中创建的OnboardingHome和OnboardingPAge ViewControllers以及为每个创建的子类创建。
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");
}
}
}
堆栈跟踪
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:
答案 0 :(得分:2)
我假设您正在使用故事板并在Xamarin的内置iOS Designer中进行编辑。
您是如何将ViewControllers添加到项目中的?根据我的经验,在Xamarin的iOS Designer中这样做的最安全的方法之一就是在视图控制器的属性中指定一个类名。
这会产生一个像这样的新VC-Class:
// public vc_onboardPage (IntPtr handle) : base (handle)
public vc_onboardPage () : base("vc_onboardPage", null)
请注意,构造函数使用IntPtr作为参数调用基础构造函数。与构造函数进行对比,构造函数使用字符串参数调用它:
var app = angular.module('app', ['ngMockE2E']);
app.controller('myController', function($scope, $http) {
$scope.offices = [];
$scope.addOffice = function() {
$scope.offices.push({
employees: []
});
};
$scope.addEmployee = function(office) {
office.employees.push({});
};
$scope.submitOffices = function() {
$http.post('/offices', $scope.offices)
.success(function() {
// Handle success.
}).error(function() {
// Handle error.
});
};
});
上次检查时,字符串参数仅在使用iOS设计器未使用的NIB / XIB时有效。因此我怀疑这可能是您的问题的根源,因为您的错误消息中也提到了字符串“vc_onboardPage”。
我会尝试执行以下操作:
随意发表评论。