gpt4 book ai didi

ios - 将事件附加到接口(interface)但不使用具体类时,Monotouch 应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 17:58:33 25 4
gpt4 key购买 nike

我有一个 MonoTouch 应用程序,它由许多 View 组成,每个 View 都有一个关联的界面和演示者。它看起来像这样:

class SomeView : UIView, ISomeView
{
public event EventHandler PreviousClicked = delegate {};
public event EventHandler NextClicked = delegate {};
public event EventHandler Loaded = delegate {};

public SomeView()
{
new SomePresenter(this);
}
}

interface ISomeView
{
event EventHandler PreviousClicked;
event EventHandler NextClicked;
event EventHandler Loaded;
event EventHandler Unloaded;
}

class SomePresenter
{
readonly ISomeView _view;

public SomePresenter(ISomeView view)
{
_view = view;
_view.Loaded += Loaded;
_view.NextClicked += NextClicked;
_view.PreviousClicked += PreviousClicked;
_view.Unloaded += Unloaded;
}

void Loaded (object sender, EventArgs e)
{
//Nothing special
}

void PreviousClicked (object sender, EventArgs e)
{
//Nothing special
}

void NextClicked (object sender, EventArgs e)
{
//Nothing special
}
}

此代码在模拟器中完美运行,但是在 iPad 上运行时,当演示者在其构造函数中将事件附加到 View 时,它将崩溃。但它以一种非常非常奇怪的方式崩溃。

首先,附加第一个事件时它不会崩溃,而是附加第二个事件,即
_view = view;
_view.Loaded += Loaded;
_view.NextClicked += NextClicked; //FAILS HERE

它返回的堆栈跟踪是
0   SomeApp              0x008f8e01 mono_handle_native_sigsegv + 244
1 SomeApp 0x0092b511 sigabrt_signal_handler + 112
2 libsystem_c.dylib 0x321817ed _sigtramp + 48
3 libsystem_c.dylib 0x3217720f pthread_kill + 54
4 libsystem_c.dylib 0x3217029f abort + 94
5 SomeApp 0x008ceccb monoeg_g_log + 122
6 SomeApp 0x008d386b get_numerous_trampoline + 134
7 SomeApp 0x008d3b33 mono_aot_get_imt_thunk + 34
8 SomeApp 0x00921be5 initialize_imt_slot + 72
9 SomeApp 0x0092294f build_imt_slots + 642
10 SomeApp 0x00922a29 mono_vtable_build_imt_slot + 80
11 SomeApp 0x008fd90d mono_convert_imt_slot_to_vtable_slot + 212
12 SomeApp 0x008fdab9 common_call_trampoline + 180
13 SomeApp 0x008fc78b mono_vcall_trampoline + 158
14 SomeApp 0x005ec748 generic_trampoline_vcall + 136
...

应该注意的是,这些 View 中的每一个都被推送到 UINavigationController 中,并且演示者可以完美地将事件附加到 View ,直到两个 View 被推送到堆栈上。

我最初的假设是 GC 正在积极收集内存,但后来我尝试删除接口(interface)并将事件附加到具体类型上,即
public SomePresenter(SomeView view)
{
_view = view;
_view.Loaded += Loaded;
_view.NextClicked += NextClicked;
_view.PreviousClicked += PreviousClicked;
_view.Unloaded += Unloaded;
}

一切正常。幽灵般的

如果有人知道这里发生了什么,我真的很想听听!

最佳答案

设备日志通常会显示一条消息,解释有关问题的更多信息。您可以从 MonoDevelop 访问设备(菜单 View -> Pads -> iOS Device Log)。

设备日志可能会说您需要增加特定类型的蹦床数量,您可以在此处阅读:http://docs.xamarin.com/ios/troubleshooting#Ran_out_of_trampolines_of_type_0

关于ios - 将事件附加到接口(interface)但不使用具体类时,Monotouch 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13415985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com