【发布时间】:2016-08-08 18:22:36
【问题描述】:
我对移动开发很陌生,如果其中一些看起来微不足道,请原谅我。但是我试图让一个基本的 PageViewController 在 Xamarin iOS 中工作,并使用我拥有的许多不同的注册控制器,用于应用程序注册的不同阶段。所以用户将填写第一页,点击继续,然后进入第二步,依此类推。
我使用了一个来自 GitHub 的示例 PageViewController 项目,并且在我的模拟器上运行良好。但是,当我尝试将它与我的注册控制器一起使用时,出现错误
Foundation.MonoTouchException:抛出 Objective-C 异常。姓名: NSUnknownKeyException 原因:[ setValue:forUndefinedKey:]:这个类不是键值 键 DateOfBirthText 的编码兼容。
这是父视图控制器的 OnLoad 方法
public override void ViewDidLoad()
{
base.ViewDidLoad();
_pageViewController = Storyboard.InstantiateViewController("SignInPageViewController") as UIPageViewController;
_pageViewController.DataSource = new PageViewControllerDataSource(this, _userInput);
var startVc = ViewControllerAtIndex(0);
var viewControllers = new[] {startVc};
_pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, false, null);
_pageViewController.View.Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Size.Height - 50);
AddChildViewController(_pageViewController);
View.AddSubview(_pageViewController.View);
_pageViewController.DidMoveToParentViewController(this);
}
在线抛出错误
_pageViewController.SetViewControllers
这是试图加载到 PageViewController 并抛出错误的子控制器的设计器代码
{
[Register ("SigninViewControllerStageOne")]
partial class SigninViewControllerStageOne
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField DateOfBirthText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField NameText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIButton NextStepButton { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField PhoneNumberText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel TitleLabel { get; set; }
void ReleaseDesignerOutlets ()
{
if (DateOfBirthText != null) {
DateOfBirthText.Dispose ();
DateOfBirthText = null;
}
if (NameText != null) {
NameText.Dispose ();
NameText = null;
}
if (NextStepButton != null) {
NextStepButton.Dispose ();
NextStepButton = null;
}
if (PhoneNumberText != null) {
PhoneNumberText.Dispose ();
PhoneNumberText = null;
}
if (TitleLabel != null) {
TitleLabel.Dispose ();
TitleLabel = null;
}
}
}
}
更新:完整堆栈跟踪
未处理的异常:
Foundation.MonoTouchException:抛出 Objective-C 异常。姓名: NSUnknownKeyException 原因:[ setValue:forUndefinedKey:]:这个类不是键值 键 DateOfBirthText 的编码兼容。
本机堆栈跟踪:
0 核心基础 0x00958494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x08fd3e02 objc_exception_throw + 50
2 核心基础 0x009580b1 -[NSException 加注] + 17
3 基础 0x014777f8 -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 基础 0x013d1e6a _NSSetUsingKeyValueSetter + 115
5 基础 0x013d1def -[NSObject(NSKeyValueCoding) setValue:forKey:] + 295
6 UIKit 0x0397b931 -[UIViewController setValue:forKey:] + 85
7 基础 0x0140654b -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 384
8 UIKit 0x03bf8a62 -[UIRuntimeOutletConnection 连接] + 132
9 libobjc.A.dylib 0x08fe800c -[NSObject 执行选择器:] + 62
10 核心基础 0x00881131 -[NSArray makeObjectsPerformSelector:] + 273
11 UIKit 0x03bf70fc -[UINib instantiateWithOwner:options:] + 2102
12 UIKit 0x03983380 -[UIViewController _loadViewFromNibNamed:bundle:] + 429
13 UIKit 0x03983db8 -[UIViewController 加载视图] + 189
14 UIKit 0x039841c4 -[UIViewController loadViewIfRequired] + 154
15 UIKit 0x03984ab1 -[UIViewController 视图] + 35
16 UIKit 0x04038649 -[UIPageViewController _setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:] + 2250
17 UIKit 0x0403a76a -[UIPageViewController setViewControllers:direction:animated:completion:] + 309
18 ??? 0x1a6a07cc 0x0 + 443156428
19 ??? 0x1a69f6d0 0x0 + 443152080
20 ??? 0x18d3200f 0x0 + 416489487
21 ??? 0x18d29c1d 0x0 + 416455709
22 BarPandaApp 0x001be859 mono_jit_runtime_invoke + 921
23 BarPandaApp 0x0027d0ce mono_runtime_invoke + 142
24 BarPandaApp 0x0035e225 xamarin_trampoline + 5605
25 UIKit 0x0397fb72 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
26 UIKit 0x03984692 -[UIViewController loadViewIfRequired] + 1384
27 UIKit 0x039d02bb -[UINavigationController _layoutViewController:] + 52
28 UIKit 0x039d0b75 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 421
29 UIKit 0x039d0d1c -[UINavigationController _startTransition:fromViewController:toViewController:] + 145
30 UIKit 0x039d2118 -[UINavigationController _startDeferredTransitionIfNeeded:] + 1038
31 UIKit 0x039d339e -[UINavigationController __viewWillLayoutSubviews] + 68
32 UIKit 0x03bb84b7 -[UILayoutContainerView layoutSubviews] + 252
33 UIKit 0x038843d4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 810
34 libobjc.A.dylib 0x08fe8059 -[NSObject performSelector:withObject:] + 70
35 石英核心 0x0b607096 -[CALayer 布局子层] + 144
36 石英核心 0x0b5fa8b6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
37 石英核心 0x0b5fa71a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
38 石英核心 0x0b5ecee7 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317
39 石英核心 0x0b621847 _ZN2CA11Transaction6commitEv + 561
40 石英核心 0x0b622108 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
41 核心基础 0x0086a75e CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30
42 核心基础 0x0086a6be __CFRunLoopDoObservers + 398
43 核心基础 0x0085f868 CFRunLoopRunSpecific + 504
44 CoreFoundation 0x0085f65b CFRunLoopRunInMode + 123
45 UIKit 0x037ae2da -[UIApplication _run] + 540
46 UIKit 0x037b3eb9 UIApplicationMain + 160
47 ??? 0x18d27144 0x0 + 416444740
48 ??? 0x18d26ef4 0x0 + 416444148
49 ??? 0x18d249a0 0x0 + 416434592
50 ??? 0x18d24620 0x0 + 416433696
51 ??? 0x18d24823 0x0 + 416434211
52 BarPandaApp 0x001be859 mono_jit_runtime_invoke + 921
53 BarPandaApp 0x0027d0ce mono_runtime_invoke + 142
54 BarPandaApp 0x002822d1 mono_runtime_exec_main + 401
55 BarPandaApp 0x00282095 mono_runtime_run_main + 645
56 BarPandaApp 0x0013a3d5 mono_jit_exec + 213
57 BarPandaApp 0x0036d73a xamarin_main + 第2474章
58 BarPandaApp 0x0036e351 主 + 65
59 libdyld.dylib 0x094ada25 开始 + 1
【问题讨论】:
-
什么是完整的错误消息(在您的问题中的剪辑消息之后应该有一些 at 行,即:
at (wrapper managed-to-native) .... at ..... at ..... -
刚刚添加了完整的堆栈跟踪
-
有趣的是,当我删除我为每个控件(在 VS IDE 设计器属性窗口中)指定的名称并将它们保留为默认控件,没有短名称来引用它们时,它可以工作
标签: ios xamarin xamarin.ios