Mvvmcross IOS with storyboard and custom UITableCell not showing
I have a problem with Xamarin (and / or Mvvmcross) when I try to use storyboards and a custom UITableCell
I saw almost the same question here Update - MvvmCross iOS with storyboards - TableViewCell is not displayed but there is no answer.
My app is written with Xamarin and Mvvmcross for iOS using storyboard
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="9">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Daily Wods List View-->
<scene sceneID="8">
<objects>
<tableViewController id="9" sceneMemberID="viewController" customClass="DailyWodsListView" storyboardIdentifier="DailyWodsListView">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="10">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="13" customClass="DailyWodCell">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="13" id="14">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="26" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES">
<rect key="frame" x="80" y="11" width="42" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="Title" destination="26" id="name-outlet-26"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="9" id="11"/>
<outlet property="delegate" destination="9" id="12"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="15" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-56" y="-165"/>
</scene>
</scenes>
<resources>
<image name="add" width="600" height="338"/>
<image name="back" width="96" height="96"/>
<image name="benchmark" width="192" height="192"/>
<image name="body" width="72" height="72"/>
<image name="burn" width="96" height="96"/>
<image name="daily" width="36" height="36"/>
<image name="logosmall" width="480" height="270"/>
<image name="bin" width="17" height="17"/>
<image name="edit" width="17" height="17"/>
<image name="topImage" width="540" height="275"/>
<image name="weight" width="12.666667" height="12.666667"/>
<image name="community.png" width="36" height="36"/>
<image name="hot.png" width="36" height="36"/>
<image name="benchmark.png" width="36" height="36"/>
<image name="daily.png" width="36" height="36"/>
<image name="settings.png" width="36" height="36"/>
</resources>
</document>
Storyboard contains UITableViewController and UITableCell (custom class: DailyWodCell)
Here is a storyboard related view
[MvxFromStoryboard("Pages")]
[MvxTabPresentation(WrapInNavigationController = true, TabIconName = "daily", TabName = "Daily")]
public partial class DailyWodsListView : MvxTableViewController<DailyWodsListViewModel>
{
public DailyWodsListView(IntPtr handle) : base(handle)
{
TableView.RegisterClassForCellReuse(typeof(DailyWodCell), DailyWodCell.Key);
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var source = new DailyWodsListSource(TableView)
{
UseAnimations = true,
AddAnimation = UITableViewRowAnimation.Left,
RemoveAnimation = UITableViewRowAnimation.Right
};
this.AddBindings(new Dictionary<object, string>
{
{source, "ItemsSource DailyWods"}
});
TableView.Source = source;
TableView.ReloadData();
}
}
Source for TableView
public class DailyWodsListSource : MvxTableViewSource
{
private NSString _cellIdentifier = new NSString(nameof(DailyWodCell));
public DailyWodsListSource(UITableView tableView)
: base(tableView)
{
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
return (DailyWodCell)tableView.DequeueReusableCell(_cellIdentifier);
}
}
And the code for the custom UITableCell
[MvxFromStoryboard("Pages")]
public partial class DailyWodCell : MvxTableViewCell
{
public static readonly NSString Key = new NSString(nameof(DailyWodCell));
private const string BindingText = @"
_Title DisplayTitle";
public DailyWodCell(IntPtr handle) : base(BindingText, handle)
{
}
public string _Title
{
get => Title.Text;
set
{
if (Title != null)
Title.Text = value;
}
}
}
And the DailyWodCell.designer.cs file:
[Register ("DailyWodCell")]
partial class DailyWodCell
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UILabel Title { get; set; }
void ReleaseDesignerOutlets ()
{
if (Title != null) {
Title.Dispose ();
Title = null;
}
}
}
Everything works fine, except "Title" (in the DailyWodCell class) is always null.
If I remove the line
TableView.RegisterClassForCellReuse(typeof(DailyWodCell), DailyWodCell.Key);
I am getting the error
UITableView (; layer =; contentOffset: {0, -64}; contentSize: {375, 396}>) could not get cell from its data source
I have read many solutions about using XIB and I tried it (it works!) But I would like to solve this problem with storyboard
source to share
No one has answered this question yet
See similar questions:
or similar: