ios - MvvmCross binding to table cell in a storyboard -
i'm developing app mvvmcross uses storyboards ui. rather using xib files table cells, i'm trying create cells within storyboard. storyboard generates class cell fine within class bind model. cells beingness created next error occurs upon binding each label within cell, 'mystringproperty' name of property i'm trying bind (either name, phonenumber or email):
failed create target binding binding text mystringproperty
the table beingness created same way in stuart's kitten cell tutorial, except instead of xib i'm using next line of code signify using generated class cell:
tableview.registerclassforcellreuse(typeof(mycell), mycell.key);
the binding of info in cell beingness done same way in stuart's kitten cell tutorial.
here code mycell
public partial class mycell : mvxtableviewcell { public static readonly nsstring key = new nsstring("mycell"); public mycell(intptr handle) : base(handle) { this.delaybind(() => { var set = this.createbindingset<mycell, contactmodel>(); set.bind(mylabelone).to(contact => contact.name); set.bind(mylabeltwo).to(contact => contact.phonenumber); set.bind(mylabelthree).to(contact => contact.email); set.apply(); }); } }
the designer:
[register ("mycell")] partial class mycell { [outlet] monotouch.uikit.uilabel mylabelone{ get; set; } [outlet] monotouch.uikit.uilabel mylabeltwo{ get; set; } [outlet] monotouch.uikit.uilabel mylabelthree{ get; set; } void releasedesigneroutlets () { if (mylabelone!= null) { mylabelone.dispose (); mylabelone= null; } if (mylabeltwo!= null) { mylabeltwo.dispose (); mylabeltwo= null; } if (mylabelthree!= null) { mylabelthree.dispose (); mylabelthree= null; } } }
i had pretty much same problem, found solution:
solution here (my question - edit important): mvvmcross ios storyboard table binding not working
apparantly fluent binding , storyboard tableviewcell
s don't work well. same true collectionviewcell
s (same solution in end, don't need custom mvxcollectionviewsource
- standard fine)
@stuart knows better, why these 2 approaches produce different results
change cell this:
public partial class mycell : mvxtableviewcell { public static readonly nsstring key = new nsstring("mycell"); private const string bindingtext = @" mylabelonetext name; mylabeltwotext phonenumber; mylabelthreetext email"; public string mylabelonetext { { homecoming mylabelone.text; } set { mylabelone.text = value; } } public string mylabeltwotext { { homecoming mylabeltwo.text; } set { mylabeltwo.text = value; } } public string mylabelthreetext { { homecoming mylabelthree.text; } set { mylabelthree.text = value; } } public mycell(intptr handle) : base(bindingtext, handle) { } }
you might want utilize custom tableviewsource (or overwrite necessary constructors in cell):
public class mytableviewsource : mvxtableviewsource { private nsstring cellidentifier = new nsstring("mycell"); public mytableviewsource(uitableview tableview) : base(tableview) { } protected override uitableviewcell getorcreatecellfor(uitableview tableview, nsindexpath indexpath, object item) { homecoming (mycell)tableview.dequeuereusablecell(cellidentifier); } }
fit needs, of import part phone call base of operations constructor mvxtableviewcell(bindingtext, handle)
i can upload project github if needed
ios xamarin mvvmcross
No comments:
Post a Comment