【发布时间】:2015-04-02 02:32:49
【问题描述】:
尝试在 Visual Studio 2013 Premium 中运行 Xamarin iOS 项目时出现问题。这意味着 LoginView.xib 不在项目的捆绑包中。
我 Mac 上的 Xamarin Studio 对此没有任何问题。
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/gtas/Library/Developer/CoreSimulator/Devices/215AE19B-D168-47F2-82D8-D5B40CDB46DE/data/Containers/Bundle/Application/33D2A0A9-F775-4B46-9041-E26EB53AF417/OnLeaveiOS.app> (loaded)' with name 'LoginView'
我使用以下代码将 xib 加载到支持的类文件中。
public LoginView(IntPtr h): base(h)
{
SetupView ();
}
public LoginView ()
{
SetupView ();
}
public LoginView (LoginRegisterViewModel vm)
{
_vm = vm;
SetupView ();
}
private void SetupView()
{
view = LoadViewFromXib ();
view.BackgroundColor = UIColor.Clear;
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
Bounds = view.Bounds;
_intrinsicContentSize = Bounds.Size;
TranslatesAutoresizingMaskIntoConstraints = false;
SetupOutlets ();
this.AddSubview (view);
}
private UIView LoadViewFromXib()
{
NSBundle bundle = NSBundle.FromClass (this.Class);
UINib nib = UINib.FromName ("LoginView", bundle);
return (UIView)nib.Instantiate (this, null)[0];
}
在编写原生 iOS 应用程序时,我使用这种技术分离了我的 UI 组件,并且一切正常。同样正如我所说,Mac Xamarin Studio 似乎并不在意它。
我使用 Storyboard 文件和 XIB 组件的组合。
【问题讨论】:
标签: c# ios visual-studio-2013 xamarin.ios xamarin-studio