Xamarin.iOS NSUnknownKeyException原因:[ setValue:forUndefinedKey:]:此类与键staticDataSource的键值编码不兼容

iovurdzv  于 2023-05-30  发布在  iOS
关注(0)|答案(2)|浏览(171)

在我的Xamarin.iOS项目中,我试图从UITableViewController推送UIViewController,但这个错误会出现在Main.cs中:

基础.MonoTouchException:Objective-C异常抛出名称:NSUnknownKeyException原因:[ setValue:forUndefinedKey:]:该类与staticDataSource键的键值编码不兼容。

我已经看到了一些关于如何修复XCode或Xamarin Studio中类似错误的建议,但我正在使用Visual Studio 2019(Windows)和iOS设计器,这些建议并不适用。我尝试过清理、重建、重新启动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”键是什么?我在项目的任何地方都找不到对那个键的引用。我如何使类键值编码兼容一个不存在的键?

roqulrg3

roqulrg31#

我找到问题所在了。
我的故事板定义

<tableViewController>

但是C#代码隐藏中的相应分部类实现了

UIViewController

解决方案是编辑C#分部类来实现

UITableViewController

结果看起来像

partial class MyController : UITableViewController
k4ymrczo

k4ymrczo2#

1.点击查看控制器
1.单击连接检查器
1.搜索任何警告标志️steps are shown in the image below

相关问题