Xamarin.iOS NSUnknownKeyException 原因:[setValue:forUndefinedKey:]:此类不支持关键值编码“staticDataSource”键。

3
在我的Xamarin.iOS项目中,我试图从UITableViewController推送一个UIViewController,但这个错误会冒泡到Main.cs:
Foundation.MonoTouchException: Objective-C异常抛出。 名称:NSUnknownKeyException Reason:[setValue:forUndefinedKey:]:此类不符合键值编码-compliant for the key staticDataSource。
我看到一些关于如何修复XCode或Xamarin Studio中类似错误的建议,但我正在使用带有iOS Designer的Visual Studio 2019(Windows),并且那些建议并不适用。我尝试了清理、重建、重启VS、重新连接到Mac服务器、重启Mac服务器以及重启计算机。
这是我的UIViewController designer.cs文件中的outlet代码:
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"/> - Omar Himada
@OmarHimada,我已经尝试删除那行代码并更改目标和ID,但没有成功。 - Jake Steed
很难在不看Storyboard代码的情况下找到原因。我建议你先删除所有连接,然后逐个添加以解决这个问题。如果你能上传一个可以重现此问题的示例,我们可以为你检查Storyboard。 - nevermore
2个回答

1

我找到了问题所在。

我的故事板定义为:

<tableViewController>

但是在 C# 代码后台中相应的部分类正在实现

UIViewController

解决方案是编辑C#部分类,改为实现。
UITableViewController

结果看起来像这样

partial class MyController : UITableViewController

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接