Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单触式。对话崩溃_C#_Ios_Crash_Xamarin.ios_Monotouch.dialog - Fatal编程技术网

C# 单触式。对话崩溃

C# 单触式。对话崩溃,c#,ios,crash,xamarin.ios,monotouch.dialog,C#,Ios,Crash,Xamarin.ios,Monotouch.dialog,我有一个小的测试应用程序,它只在3个页面之间循环。 以下是AppDelegate: public override bool FinishedLaunching (UIApplication app, NSDictionary options) { _session = new Session(); _session.NextScreen += (screenIndex) => { window.Ro

我有一个小的测试应用程序,它只在3个页面之间循环。 以下是AppDelegate:

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        _session = new Session();
        _session.NextScreen += (screenIndex) => 
        {
            window.RootViewController = _viewControllers[screenIndex];
        };

        _viewControllers.Add(new Screen0(_session));
        _viewControllers.Add(new Screen1(_session));
        _viewControllers.Add(new Screen2(_session));

        // create a new window instance based on the screen size
        window = new UIWindow (UIScreen.MainScreen.Bounds);

        // If you have defined a view, add it here:
        // window.AddSubview (navigationController.View);
        window.RootViewController = _viewControllers[0];

        // make the window visible
        window.MakeKeyAndVisible ();

        return true;
如果我在每个屏幕上放置一个按钮,我可以在页面之间导航,即

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        UIButton button = new UIButton(new RectangleF(30, 200, 80, 34));
        button.SetTitle("Go to 1", UIControlState.Normal);
        button.TouchUpInside += (sender, e) => 
        {
            _session.ExittingScreen = 0;
        };
        View.AddSubview(button);
    }
但是,当我使用MonoTouch.Dialog时,会出现间歇性崩溃。这是我的密码:

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        var rootElement = new RootElement("Register")
        {
            new Section()
            {
                new EntryElement("First Name", "required", ""),
                new EntryElement("Last Name", "required", ""),
                new EntryElement("Email Address", "required", ""),
                new EntryElement("Password", "required", "")
            },
            new Section()
            {
                new StyledStringElement("Submit you information", () => { _session.ExittingScreen = 1; })
            }
        };
        var dialogViewController = new DialogViewController(rootElement);
        var navigationController = new UINavigationController(dialogViewController);

        View.Add (navigationController.View);
垃圾场:

在包装器中,管理本机MonoTouch.UIKit.UIApplication.UIApplicationMain int,字符串[],intptr,intptr 位于MonoTouch.UIKit.UIApplication.Main字符串[],字符串,字符串 位于MTD.Application.Main字符串[] 在包装器运行时调用。运行时调用对象,intptr,intptr,intptr

本机堆栈跟踪:

0   MTD                                 0x00090b7c mono_handle_native_sigsegv + 284
1   MTD                                 0x00005f28 mono_sigsegv_signal_handler + 248
2   libsystem_c.dylib                   0x97da559b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   UIKit                               0x02220952 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 201
5   Foundation                          0x0173786d __NSFireDelayedPerform + 389
6   CoreFoundation                      0x01195966 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
7   CoreFoundation                      0x01195407 __CFRunLoopDoTimer + 551
8   CoreFoundation                      0x010f87c0 __CFRunLoopRun + 1888
9   CoreFoundation                      0x010f7db4 CFRunLoopRunSpecific + 212
10  CoreFoundation                      0x010f7ccb CFRunLoopRunInMode + 123
11  GraphicsServices                    0x04789879 GSEventRunModal + 207
12  GraphicsServices                    0x0478993e GSEventRun + 114
13  UIKit                               0x02190a9b UIApplicationMain + 1175
14  ???                                 0x09ff6774 0x0 + 167733108
15  ???                                 0x09ff5958 0x0 + 167729496
16  ???                                 0x09ff57f0 0x0 + 167729136
17  ???                                 0x09ff587f 0x0 + 167729279
18  MTD                                 0x0000a292 mono_jit_runtime_invoke + 722
19  MTD                                 0x0016a17e mono_runtime_invoke + 126
20  MTD                                 0x0016e264 mono_runtime_exec_main + 420
21  MTD                                 0x00173685 mono_runtime_run_main + 725
22  MTD                                 0x00067495 mono_jit_exec + 149
23  MTD                                 0x002116c9 main + 2825
24  MTD                                 0x000032e5 start + 53
25???0x00000005 0x0+5

我做错了什么,还是这是一个错误?谢谢。

避免以下模式:

var navigationController = new UINavigationController(dialogViewController);
View.Add (navigationController.View);
因为一旦View.Add调用完成,navigationController就不会在托管端被引用,垃圾回收器可以随时处理它。然而,从本机的角度来看,它将是存在的。从本机到托管再到已处置实例的调用将使应用程序崩溃

正确的模式是将navigationController声明为字段而不是您类型的局部变量,并在方法中创建/分配它。只要父实例存在,这将保持对navigationController的引用处于活动状态,并确保任何回调都不会转到已释放的对象

例如


只是想澄清一下,当我触摸Submit SyledStringElementThank时,它崩溃了。这似乎阻止了间歇性的撞车。好消息:-行,如3???0xFFFFFFFF0x0+4294967295,通常指向从本机帧调用时不再存在的实例。
private UINavigationController navigationController;
...
public override void ViewDidLoad ()
{
    ...
    var dialogViewController = new DialogViewController(rootElement);
    navigationController = new UINavigationController(dialogViewController);

    View.Add (navigationController.View);
    ...
}