【发布时间】:2019-08-14 02:05:31
【问题描述】:
在我的 Xamarin.iOS 项目中,我尝试从 UITableViewController 推送 UIViewController,但此错误冒泡到 Main.cs:
Foundation.MonoTouchException:抛出 Objective-C 异常。名称:NSUnknownKeyException 原因:[ setValue:forUndefinedKey:]:此类与键 staticDataSource 的键值编码不兼容。
我看到了一些关于如何在 XCode 或 Xamarin Studio 中修复类似错误的建议,但我将 Visual Studio 2019 (Windows) 与 iOS 设计器一起使用,但该建议并不适用。我已经尝试过清理、重建、重新启动 VS、重新连接到 Mac 服务器、重新启动 Mac 服务器和重新启动我的计算机。
这是我的 UIViewController Designer.cs 文件中的插座代码:
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;
}
}
}
}
这是我的故事板中的相关节点:
<!--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”键是什么?我在项目的任何地方都找不到对该键的引用。对于不存在的键,如何使类键值编码兼容?
【问题讨论】:
-
我最好的猜测是这里有问题:
<outlet property="dataSource" destination="9062" id="9064"/> -
@OmarHimada 我已经尝试删除该行并更改目标和 ID,但没有运气。
-
看故事板代码很难找到原因。我建议您做的是删除所有连接,然后将它们一一添加以解决此问题。如果您可以上传可以重现此问题的示例,我们可以为您检查情节提要。
标签: c# ios xamarin.ios