Reputation: 45135
Using Xamarin and a custom table cell (derived from UITableViewCell), this works fine:
[Register("MyCell")]
public class MyCell: UITableViewCell
{
private UILabel myLabel;
public MyCell(IntPtr handle)
: base(handle)
{
myLabel= new UILabel()
{
Font = UIFont.SystemFontOfSize(16),
Text = "My Label",
BackgroundColor = UIColor.Cyan
};
ContentView.Add(myLabel);
}
}
However, if I derive from MvxTableViewCell
instead (because I ultimately want my cell to be data bound) I have an exception thrown on the ContentView.Add(myLabel)
line:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
This is before any attempt to bind any data.
Any ideas what is going on? What's the right way to create a custom cell in code using Mvx? I've had custom cells work with Mvx using .xib
files, but they seem to be a little clunky to use when trying to work with visual studio on the PC and Xamarin studio on the Mac.
Upvotes: 0
Views: 383
Reputation: 66882
If your code is exactly as above except with UITableViewCell
replaced with MvxTableViewCell
and you haven't done any binding externally to change this, then there's nothing in MvxTableViewCell that should cause this - from MvxTableViewCell.cs - it's just a simple layer on top of UITableViewCell
In my opinion, your best bet is to collect a bit more basic information:
TargetInvocationException
? If so, where is that inner exception thrown?If you can work that out, then you might have more chance in debugging and solving the problem
Upvotes: 1