xamarin.ios - Xamarin iOS 在 NSBundle.MainBundle.LoadNib("CustomView", this, null) 中崩溃
问题描述
我创建了新的 CustomView.xib 文件并与代码隐藏类相关联。但是当我尝试初始化视图时,应用程序崩溃了,如下所述的错误。
MonoTouch:无法安装 sigaction 覆盖,意外的 sigaction 实施。
NSBundle.MainBundle.LoadNib("CustomView", this, null); // 应用程序在此处崩溃。
CS类文件:
public partial class CustomView : UIView
{
public CustomView(IntPtr handle) : base(handle)
{
}
public override void AwakeFromNib()
{
base.AwakeFromNib();
}
}
设计师类:
[Register("CustomView")]
partial class CustomView
{
[Outlet]
UIKit.UIView contentView { get; set; }
void ReleaseDesignerOutlets ()
{
if (contentView != null) {
contentView.Dispose ();
contentView = null;
}
}
}
笔记:
- 构建操作设置为 interfaceDefinition。
- xib 的文件所有者设置为类名“CustomView”
- 还实现了 AwakeFromNib 覆盖方法。
提前致谢。
编辑:
很长一段时间后,我们遇到了类似的问题,但在 AwakeFromNib 方法中的“contentView”上显示“Object Null Reference”有不同的例外。当您尝试访问 AwakeFromNib 方法中的 ContentView 时,应用程序崩溃。这仅发生在 iOS 9.3.x 上。如果某人面临同样的问题,以下修复可能会对他们有所帮助。
[Export("initWithFrame:")]
public SampleHeaderView(CGRect frame) : base(frame)
{
Initialize();
}
[Export("initWithCoder:")]
public SampleHeaderView(NSCoder coder) : base(coder)
{
Initialize();
}
public override void AwakeFromNib()
{
base.AwakeFromNib();
}
private void Initialize()
{
if (this.ContentView != null)
{
this.ContentView.BackgroundColor = UIColor.Red();
}
}
解决方案
推荐阅读
- python - 使用 OpenCV python 进行伽马校正的问题
- java - 修改 PB 配置时,ProcessBuilder 产生了进程行为
- python-3.x - 在 Spyder 4.0 中隐藏 runfile() 命令
- sql - 在输出中使用计数函数查看优化
- laravel - Laravel - 如何创建递归选择选项下拉列表
- php - 字段为空时 ACF if 语句不起作用
- sql - Visual Studio 代码与 SQL 格式化
- reactjs - 反应中的功能图
- symfony - 使用 PHP Doctrine ORM 加入 0..n / 0..n 关系链接的 2 个表
- java - 线程“主”java.lang.NoSuchFieldError 中的异常:LINUX