2016-05-21 11 views
2

この質問は何百万回も尋ねられましたが、私はStuart Lodgeのチュートリアル "N + 1日MvvmCrossの "、N = 11、CollectionView。チュートリアルを見ながら私が編集している別のプロジェクトがあるので、私は100%に従っていないので、何かを見逃してしまったと確信しています。ここでは、完全なエラーメッセージです:MvvmCross/Xamarin "このクラスはキーのコード値に符合したキー値ではありません"

Foundation.MonoTouchException: Objective-C exception thrown. 
Name: NSUnknownKeyException Reason: [<NSObject 0x796c2460>  
setValue:forUndefinedKey:]: this class is not key value 
coding-compliant for the key MyLabel. 

が、私はこれはXIBにコントロールを追加する場合であるとは考えていないTestItemView

の自動生成部分クラスの有効なコンセントがあるように見えますそれを取り除いて、撚り合わせられた接続ができるようにします。これは、xibを削除してもう一度やり直すと起こります。私は "FirstView:MvxCollectionViewController"を持っていて、私は "TestItemView:MvxCollectionViewCell"を持っています。これは "KittenCollectionCell"のスタンドインです。 FirstView、TestItemView、およびTestItemView.xibのソースコードを以下に示します。

FirstView:

ここ
using System.Drawing; 
using MvvmCross.Binding.BindingContext; 
using MvvmCross.iOS.Views; 
using Foundation; 
using MvvmCross.Binding.iOS.Views; 
using UIKit; 

namespace FirstDemo.Core.iOS.Views 
{ 
    [Register("FirstView")] 
    public class FirstView : MvxCollectionViewController 
    { 
     private bool _isInitialized = false; 
     public FirstView() : base(new UICollectionViewFlowLayout() { 
      ItemSize = new SizeF(240, 400), 
      ScrollDirection = UICollectionViewScrollDirection.Horizontal 
     }) 
     { 
      _isInitialized = true; 
      ViewDidLoad(); 
     } 

     public sealed override void ViewDidLoad() 
     { 
      if (!_isInitialized) 
       return; 

      base.ViewDidLoad(); 
      //var source = new MvxStandardTableViewSource(TestItemsTableView, "TitleText Name;"); 
      //TestItemsTableView.Source = source; 
      CollectionView.RegisterNibForCell(TestItemView.Nib, TestItemView.Key); 
      var source = new MvxCollectionViewSource(CollectionView, TestItemView.Key); 
      CollectionView.Source = source; 

      var set = this.CreateBindingSet<FirstView, Core.ViewModels.FirstViewModel>(); 
          set.Bind(source).To(vm => vm.TestItemViewModels); 
      set.Apply(); 
      CollectionView.ReloadData(); 
      } 
    } 
} 

TestItemViewのために部分的ハンドコーディングされています。ここでは

using System; 
using FirstDemo.Core.ViewModels; 
using Foundation; 
using MvvmCross.Binding.BindingContext; 
using MvvmCross.Binding.iOS.Views; 
using UIKit; 

namespace FirstDemo.Core.iOS 
{ 
    public partial class TestItemView : MvxCollectionViewCell 
    { 
     public static readonly UINib Nib = UINib.FromName("TestItemView", NSBundle.MainBundle); 
     public static readonly NSString Key = new NSString("TestItemView"); 

     public TestItemView(IntPtr handle) 
      : base(string.Empty /* TODO - this isn't really needed - mvx bug */, handle) 
     { 
      this.DelayBind(() => 
      { 
       var set = this.CreateBindingSet<TestItemView, TestItemViewModel>(); 
       set.Bind(MyLabel).To(testItem => testItem.Name); 
       set.Apply(); 
      }); 
     } 

     public static TestItemView Create() 
     { 
      return (TestItemView)Nib.Instantiate(null, null)[0]; 
     } 
    } 
} 

が自動生成された部分:

// WARNING 
// 
// This file has been generated automatically by Xamarin 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 FirstDemo.Core.iOS 
{ 
    [Register ("TestItemView")] 
    partial class TestItemView 
    { 
     [Outlet] 
     [GeneratedCode ("iOS Designer", "1.0")] 
     UILabel MyLabel { get; set; } 

     [Outlet] 
     [GeneratedCode ("iOS Designer", "1.0")] 
     UIView TestItemInfo { get; set; } 

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

そして最後に、 TestItemViewのための悪名高いxib:

<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"><dependencies><plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/></dependencies><objects><placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="TestItemView"><connections><outlet property="MyLabel" destination="28" id="name-outlet-28"/><outlet property="TestItemInfo" destination="1" id="name-outlet-1"/></connections></placeholder><placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/><view contentMode="scaleToFill" id="1"><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="custom" customColorSpace="calibratedWhite"/><subviews><label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" minimumFontSize="10" id="28" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES"><rect key="frame" x="235" y="172" width="42" height="21"/><color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/><fontDescription key="fontDescription" type="system" pointSize="17"/><color key="textColor" cocoaTouchSystemColor="darkTextColor"/><nil key="highlightedColor"/></label></subviews><userDefinedRuntimeAttributes><userDefinedRuntimeAttribute keyPath="accessibilityIdentifier" type="string" value="MyTestItem"/></userDefinedRuntimeAttributes></view></objects></document> 

誰かが手がかりを持っていれば、私は完全に迷っているので、助けていただければ幸いです。

ありがとうございます!

答えて

0

私は迅速なアプローチには親身ではありません。しかし、objective-cでは、XIBのコンセントオブジェクトをコードに手動で追加する必要があります。また、XIBのビューが古いビューのアドレスにリンクされている場合、このエラーが表示されます。したがって、objective-cでは以下の手順を実行しました。

  • は、名前mylabelという
  • でXIB
  • ラベルの検索をあなたを開く必要があれば(それがリンクしているオブジェクト)接続
  • を確認し、リンクコンセントを削除して、もう一度それを追加します。
関連する問題