Reputation: 133
In my Xamarin.iOS project, I'm trying to push a UIViewController from a UITableViewController, but this error bubbles up to the Main.cs:
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSUnknownKeyException Reason: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key staticDataSource.
I've seen some advice on how to fix similar errors in XCode or Xamarin Studio, but I'm using Visual Studio 2019 (Windows) with the iOS Designer, and that advice isn't as applicable. I've tried cleaning, rebuilding, restarting VS, reconnecting to the Mac server, restarting the Mac server, and restarting my computer.
Here is the outlet code in my UIViewController designer.cs file:
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;
}
}
}
}
Here is the relevant node in my 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>
What is the key "staticDataSource" in the error message? I can't find a reference to that key anywhere in the project. How do I make the class key value coding-compliant for a key that doesn't exist?
Upvotes: 3
Views: 675
Reputation: 1
Upvotes: 0
Reputation: 133
I figured out the problem.
My storyboard defined
<tableViewController>
But the corresponding partial class in the C# code-behind was implementing
UIViewController
The solution was to edit the C# partial class to instead implement
UITableViewController
The result looks like
partial class MyController : UITableViewController
Upvotes: 1