MonoTouch 中事件变为空

发布于 2024-10-07 08:23:36 字数 944 浏览 0 评论 0原文

嗨 Monotouch 用户, 我遇到了这种奇怪的情况,我在自定义 UIView 中声明了一个自定义事件,如下所示:

public delegate void SelectionChangedHandler(SelectableView selectedView, bool selected);
public event SelectionChangedHandler SelectionChanged;

然后我在视图控制器的初始化方法中分配给该处理程序,如下所示:

SelectableView s;
...
SelectableView.SelectionChanged += HandleSelectionChanged;

我已检查并确保所有必要的对象仍然存在于内存中并且没有被垃圾收集。

我发现该事件在作业和绘图之间的某个时候变得无效。 以前有人遇到过这个问题吗?或者我在 MonoTouch 中使用事件时做了一些明显错误的事情?

编辑: 一些附加信息 - UIView 是从 xib 文件加载的。我刚刚尝试使用未从 xib 加载的 UIView,一切正常:|我有点傻眼了。

编辑2: 更多信息:从 xib 加载的 UIView 上设置的所有属性似乎也变为 null! 下面是我用来从 xib 加载 UIView 的代码:

var v = new SelectableView(NSBundle.MainBundle.LoadNib("SelectableView", this, null).ValueAt(0));

然后我在 v 上设置一个属性:

v.SomeProperty = s;

按渲染时间 SomeProperty 为 null。

干杯 纳伦

Hi Monotouch users,
I have this strange situation where I have a custom event declared in a custom UIView like so:

public delegate void SelectionChangedHandler(SelectableView selectedView, bool selected);
public event SelectionChangedHandler SelectionChanged;

I then assign to this handler in the initialize method of a viewcontroller like so:

SelectableView s;
...
SelectableView.SelectionChanged += HandleSelectionChanged;

I have checked and ensured that all the necessary objects still exist in memory and have not been garbage collected.

I am finding that the event becomes null sometime between the assignment and the drawing.
Has anybody come across this issue before? Or am I doing something obviously wrong in my use of events in MonoTouch?

EDIT:
Some additional information - the UIView is loaded from a xib file. I just tried with a UIView not loaded from a xib and everything works fine :| I am a little dumbfounded.

EDIT 2:
Even more information: All the properties set on the UIView loaded from the xib appear to become null as well!
Here is the code I use to load the UIView from the xib:

var v = new SelectableView(NSBundle.MainBundle.LoadNib("SelectableView", this, null).ValueAt(0));

I then set a property on v:

v.SomeProperty = s;

By render time SomeProperty is null.

Cheers
Naren

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年 2024-10-14 08:23:36

我在尝试使用 Interface Builder 创建的 UIView 时遇到了很多问题。我找到了两种解决方法:1)使用 UIViewController 代替,这会占用更多内存,或者 2)在代码中创建 UIView(没有 xib 文件),这比使用 IB 稍微不太舒服。

大多数时候我最终都会选择第一个选项 - 只需注意当前加载的视图控制器的数量。

I ran into a lot of issues trying to use Interface Builder created UIViews. I found two workarounds: 1) Use a UIViewController instead, which uses up quite a bit more memory, or 2) Create the UIView in code (no xib file), which is somewhat less comfortable than using IB.

I end up going with the first option most of the time - just be aware of the number of currently-loaded viewcontrollers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文