添加子视图 - Monotouch

发布于 2024-12-17 21:16:12 字数 795 浏览 1 评论 0原文

我有一个 MonoTouch 选项卡视图应用程序。在我的一个选项卡上,当用户单击按钮时,我想显示另一个视图。我使用以下代码执行此操作:

UIView.BeginAnimations("flip");
UIView.SetAnimationDuration(1);
UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromRight, View, true);

NewFilesViewController newFilesViewController = new NewFilesViewController();
newFilesViewController.View.Frame = new System.Drawing.RectangleF(View.Frame.Top, this.View.Frame.Left, this.View.Frame.Width, this.View.Frame.Height);

View.AddSubview(newFilesViewController.View);
UIView.CommitAnimations();

在新视图上,当我单击按钮时,出现错误:

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.

我应该将视图添加到窗口吗?有更好的方法吗?

I have a MonoTouch tab view application. On one of my tabs, when a user clicks a button, I want to show another view. I do this with the following code:

UIView.BeginAnimations("flip");
UIView.SetAnimationDuration(1);
UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromRight, View, true);

NewFilesViewController newFilesViewController = new NewFilesViewController();
newFilesViewController.View.Frame = new System.Drawing.RectangleF(View.Frame.Top, this.View.Frame.Left, this.View.Frame.Width, this.View.Frame.Height);

View.AddSubview(newFilesViewController.View);
UIView.CommitAnimations();

On the new view, when I click a button, I get an error:

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.

Should I be adding the view to the window instead? Is there a better way to do this?

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

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

发布评论

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

评论(1

眼眸印温柔 2024-12-24 21:16:12

这很可能(代码没有足够的上下文来 100% 确定),因为代码后面的任何地方都没有引用 newFilesViewController 。因此,它可以在下次调用垃圾收集器 (GC) 时被处理。然而,除了视图之外,本机代码仍然存在,并且当它尝试调用(已处置的)实例时将会崩溃。

修复:将您的 newFilesViewController 局部变量提升为字段。这将使引用保持活动状态(只要类型的实例处于活动状态)并且 GC 不会收集它。

This is likely (the code does not have enough context to be 100% sure) because newFilesViewController is not referenced anywhere later in the code. As such it can be disposed the next time the Garbage Collector (GC) is invoked. However the native code still except the view to exists and this will crash when it tries to call the (disposed) instance.

Fix: Promote your newFilesViewController local variable to a field. That will keep the reference alive (as long as the type's instance is alive) and the GC won't collect it.

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