在我的 Xamarin.iOS 项目中,我试图从 UITableViewController 推送 UIViewController,但此错误会冒泡到 Main.cs:
Foundation.MonoTouchException:抛出 Objective-C 异常。名称:NSUnknownKeyException 原因:[setValue:forUndefinedKey:]:此类对于键 staticDataSource 不符合键值编码。
我看到了一些关于如何修复 XCode 或 Xamarin Studio 中的类似错误的建议,但我将 Visual Studio 2019 (Windows) 与 iOS Designer 结合使用,该建议并不适用。我试过清理、重建、重新启动 VS、重新连接到 Mac 服务器、重新启动 Mac 服务器以及重新启动我的计算机。
这是我的 UIViewController designer.cs 文件中的 socket 代码:
namespace TestProject.iOS.Controllers.Status_Change
{
[Register ("ReturnTimeViewController")]
partial class ReturnTimeViewController
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UIDatePicker ReturnDatePicker { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UIDatePicker ReturnTimePicker { get; set; }
void ReleaseDesignerOutlets ()
{
if (ReturnDatePicker != null) {
ReturnDatePicker.Dispose ();
ReturnDatePicker = null;
}
if (ReturnTimePicker != null) {
ReturnTimePicker.Dispose ();
ReturnTimePicker = null;
}
}
}
}
这是我 Storyboard中的相关节点:
<!--Return Time View Controller-->
<scene sceneID="9061">
<objects>
<tableViewController storyboardIdentifier="ReturnTimeViewController" id="9062" customClass="ReturnTimeViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="9063">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<sections>
<tableViewSection headerTitle="Return Date" id="9205">
<cells>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="44" id="9206">
<rect key="frame" x="0.0" y="22" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="9206" id="9207">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<datePicker contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="date" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="9212" ambiguous="YES">
<rect key="frame" x="0.0" y="0.0" width="320" height="212"/>
<color key="tintColor" red="0.0" green="0.52549019607843139" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<date key="date" timeIntervalSinceReferenceDate="332704801.65417802">
<!--2011-07-18 18:00:01 +0000-->
</date>
<date key="minimumDate" timeIntervalSinceReferenceDate="489060000">
<!--2016-07-01 10:00:00 +0000-->
</date>
</datePicker>
</subviews>
<constraints>
<constraint firstItem="9212" firstAttribute="centerX" secondItem="9207" secondAttribute="centerX" id="9297"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Return Time" id="9213">
<cells>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="44" id="9214">
<rect key="frame" x="0.0" y="88" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="9214" id="9215">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<datePicker contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="time" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="9220" ambiguous="YES">
<rect key="frame" x="0.0" y="0.0" width="320" height="240"/>
<color key="tintColor" red="0.0" green="0.52549019607843139" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<date key="date" timeIntervalSinceReferenceDate="332704801.65417802">
<!--2011-07-18 18:00:01 +0000-->
</date>
</datePicker>
</subviews>
<constraints>
<constraint firstItem="9220" firstAttribute="centerX" secondItem="9215" secondAttribute="centerX" id="9298"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="9062" id="9064"/>
<outlet property="delegate" destination="9062" id="9065"/>
</connections>
</tableView>
<connections>
<outlet property="ReturnTimePicker" destination="9220" id="name-outlet-9220"/>
<outlet property="ReturnDatePicker" destination="9212" id="name-outlet-9212"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="9068" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2462" y="2993"/>
</scene>
错误消息中的键“staticDataSource”是什么?我在项目的任何地方都找不到对该 key 的引用。如何使不存在的键的类键值编码兼容?
最佳答案
我发现了问题。
我的 Storyboard已定义
<tableViewController>
但 C# 代码隐藏中相应的部分类正在实现
UIViewController
解决方案是编辑 C# 部分类来代替实现
UITableViewController
结果是这样的
partial class MyController : UITableViewController
关于c# - Xamarin.iOS NSUnknownKeyException 原因 : [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key staticDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57464644/