gpt4 book ai didi

ios - 使用 MvvmCross 和 Xamarin 加载 .xib

转载 作者:行者123 更新时间:2023-12-01 19:52:15 24 4
gpt4 key购买 nike

我现在正在梳理头发。我一直在尝试从插件加载一个非常简单的 View ,但不断收到不同的错误。我做的最后一次尝试给了我以下错误:

'Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: -[UIViewController _loadViewFromNibNamed:bundle:] loaded the "PincodeView" nib but the view outlet was not set.'



这是.xib:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" launchScreen="NO">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PincodeViewController">
<connections>
<outlet property="RootView" destination="7" id="name-outlet-7"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<viewController id="6">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="4"/>
<viewControllerLayoutGuide type="bottom" id="5"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="7">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<point key="canvasLocation" x="-407" y="-274"/>
</viewController>
</objects>
</document>

里面真的不多。我只是添加了一个 ViewController,就是这样。
这是文件的所有者和 .designer.cs
using MvvmCross.iOS.Views;
using NN.Plugin.Utils.iOS.IOC;
using NN.Plugin.Utils.ViewModels;

namespace NN.Plugin.Utils.iOS
{
public partial class PincodeViewController : MvxViewController<PincodeViewModel>
{
public PincodeViewController () : base ("PincodeView", null)
{
}

public override void ViewDidLoad()
{
base.ViewDidLoad();
}
}
}

// WARNING
//
// This file has been generated automatically by Visual Studio from the outlets and
// actions declared in your storyboard file.
// Manual changes to this file will not be maintained.
//
using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;

namespace NN.Plugin.Utils.iOS
{
[Register ("PincodeViewController")]
partial class PincodeViewController
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UIView RootView { get; set; }

void ReleaseDesignerOutlets ()
{
if (RootView != null) {
RootView.Dispose ();
RootView = null;
}
}
}
}

我在 FirstView.xib 上放了一个按钮并将其绑定(bind)到 FirstViewModel.cs 中的 ICommand . FirstView显示正确。当我单击按钮时,我收到上面的错误。
这是 FirstViewModel.cs将 ICommand 绑定(bind)到 FirstView.xib 中的按钮的代码.
using MvvmCross.Core.ViewModels;
using NN.Plugin.Utils.ViewModels;
using System.Windows.Input;
using System;

namespace PluginsTester.Core.ViewModels
{
public class FirstViewModel
: MvxViewModel
{
public override void Start()
{
base.Start();

// ShowViewModel<PincodeViewModel>();
}

string hello = "Hello MvvmCross";
public string Hello
{
get { return hello; }
set { SetProperty(ref hello, value); }
}

public ICommand PinClicked
{
get => new MvxCommand(() => OpenPin());
}

private void OpenPin()
{
ShowViewModel<PincodeViewModel>();
}
}
}

我整天都在这,但还没有更进一步。所有这一切都伴随着 VS2017 的崩溃/挂起以及设计师整天放弃我。任何帮助表示赞赏。

最佳答案

好的,问题是这样的。我拿错了.xib。 Apple -> Empty User Interface 和 Apple -> View 之间似乎存在差异

Select Project

教训是:不要使用空用户界面,而是使用 View Controller 。后者创建一个 .cs 和一个 .xib 文件,工作得很好。

关于ios - 使用 MvvmCross 和 Xamarin 加载 .xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45052836/

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