Xamarin上的PageViewController不会加载子内容

时间:2016-08-08 18:22:36

标签: ios xamarin xamarin.ios

我是移动开发人员的新手,请原谅我,如果其中一些似乎微不足道。但是我试图让一个基本的PageViewController在Xamarin iOS中运行,我有许多不同的注册控制器,用于app注册的不同阶段。因此,用户将填写第一页,单击“继续”并转到第二步,依此类推。

我使用了一个来自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 CoreFoundation 0x00958494   __exceptionPreprocess + 180

     

1 libobjc.A.dylib 0x08fd3e02   objc_exception_throw + 50

     

2 CoreFoundation 0x009580b1 - [NSException   提高] + 17

     

3基金会0x014777f8    - [NSObject(NSKeyValueCoding)setValue:forUndefinedKey:] + 282

     

4基金会0x013d1e6a   _NSSetUsingKeyValueSetter + 115

     

5 Foundation 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   performSelector:] + 62

     

10 CoreFoundation 0x00881131 - [NSArray   makeObjectsPerformSelector:] + 273

     

11 UIKit 0x03bf70fc - [UINib   instantiateWithOwner:options:] + 2102

     

12 UIKit 0x03983380 - [UIViewController   _loadViewFromNibNamed:bundle:] + 429

     

13 UIKit 0x03983db8 - [UIViewController   loadView] + 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 p ??? 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 QuartzCore 0x0b607096 - [CALayer   layoutSublayers] + 144

     

36 QuartzCore 0x0b5fa8b6   _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388

     

37 QuartzCore 0x0b5fa71a   _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26

     

38 QuartzCore 0x0b5ecee7   _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317

     

39 QuartzCore 0x0b621847   _ZN2CA11Transaction6commitEv + 561

     

40 QuartzCore 0x0b622108   _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92

     

41 CoreFoundation 0x0086a75e    CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30

     

42 CoreFoundation 0x0086a6be   __CFRunLoopDoObservers + 398

     

43 CoreFoundation 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 p ??? 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 main + 65

     

59 libdyld.dylib 0x094ada25 start + 1

1 个答案:

答案 0 :(得分:0)

实际上,我认为您不应该使用UIPageViewController来实现注册进度。

但是如果你只是需要它,我会为其他人写一个样本,你可以查看这个链接来获取它:

xamarin.ios implement PageController with images only code

我建议您使用UINavigationController,它可以满足您的所有需求,有一个例子:

这是AppDelegate的代码(覆盖方法" FinishedLaunching"):

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
        SignUpStepViewController step1 = new SignUpStepViewController (1, UIColor.Red);
        SignUpStepViewController step2 = new SignUpStepViewController (2, UIColor.Green);
        SignUpStepViewController step3 = new SignUpStepViewController (3, UIColor.Blue);
        step1.SetNextController(step2);
        step2.SetNextController(step3);

        UINavigationController myNavigationController = new UINavigationController (step1);
        this.Window = new UIWindow (UIScreen.MainScreen.Bounds);
        this.Window.RootViewController = myNavigationController;
        this.Window.MakeKeyAndVisible ();
        return true;
    }

这是SignUpStepViewController的代码:

public class SignUpStepViewController : UIViewController
{
    public SignUpStepViewController (int index,UIColor color)
    {
        this.Title = "Step " + index;
        this.View.BackgroundColor = color;
    }

    public void SetNextController(SignUpStepViewController nextC)
    {
        UIBarButtonItem btnContinue = new UIBarButtonItem ("Continue",UIBarButtonItemStyle.Done, delegate {
            this.NavigationController.PushViewController(nextC,true);
        });
        this.NavigationItem.SetRightBarButtonItem (btnContinue,true);
    }
}

希望它可以帮到你。

如果您仍需要帮助,请将此消息留在此处,我会检查后者。