Как создать Custom UITableView с кнопкой из результатов Api JSON? IOS - PullRequest
0 голосов
/ 10 сентября 2018

Я новичок в Mvvmcross.iOS Я хотел бы создать Tableview с пользовательским TableSource

это мой взгляд

public partial class InterestsView : MvxViewController
{
    private InterestsViewModel _interestsViewModel;

    public InterestsView() : base("InterestsView", null)
    {
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();


        _interestsViewModel = ViewModel as InterestsViewModel;

        UIGraphics.BeginImageContext(this.View.Frame.Size);
        UIImage i = UIImage.FromFile("Home.jpg");
        i = i.Scale(this.View.Frame.Size);
        this.View.BackgroundColor = UIColor.FromPatternImage(i);


        // Perform any additional setup after loading the view, typically from a nib.
        var source = new TableSource(tableView,_interestsViewModel);

        //this.CreateBinding(source).To((InterestsViewModel vm) => vm.Interestsget).Apply();

        tableView.Source = source;
        //tableView.ReloadData();



        var set = this.CreateBindingSet<InterestsView, InterestsViewModel>();
        set.Bind(source).To(vm => vm.Interestsget);
        set.Apply();
        tableView.ReloadData();


    }


}

Хорошо, а вот и пользовательский источник

 public class TableSource : MvxStandardTableViewSource
{
    private InterestsViewModel _interestsViewModelsource;
    string cellIdentifier = "InterestsCell";
    public TableSource(UITableView tableView, InterestsViewModel InterestsViewModel )
        : base(tableView)
    {
        UseAnimations = true;
        AddAnimation = UITableViewRowAnimation.Top;
        RemoveAnimation = UITableViewRowAnimation.Middle;

        _interestsViewModelsource = InterestsViewModel;

        TableView.RegisterClassForCellReuse(typeof(InterestsCell), InterestsCell.Key);

    }


    protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
    {
        var cell = tableView.DequeueReusableCell(InterestsCell.Key);

        return cell;
    }
    public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
    {
        return 95;
    }
}

Моя ячейка, в которой используется кнопка

 public partial class InterestsCell : MvxTableViewCell
{
    public static readonly NSString Key = new NSString("InterestsCell");
    public static readonly UINib Nib;
    private UIButton btnProjectName;

    static InterestsCell()
    {
        Nib = UINib.FromName("InterestsCell", NSBundle.MainBundle);
    }

    protected InterestsCell(IntPtr handle) : base(handle)
    {
        // Note: this .ctor should not contain any initialization logic.

        this.DelayBind(() => {
            var set = this.CreateBindingSet<InterestsCell, Interests>();
            set.Bind(interestsButton).To(ii => ii.Name);
            set.Apply();
        });
    }
}

Теперь пришло время для моей ViewModel

public class InterestsViewModel : MvxViewModel
{

    public override void ViewAppearing()
    { 
        base.ViewAppearing();

        //InterestsGenesisService : I_InterestsGenesisService
        I_InterestsGenesisService _interestsGenesisService = new InterestsGenesisService();

        // Interestss.AddRange(_interestsGenesisService.AddAccount(1, 1));


        Interestsget = new List<Interests>();


        try
        {

            Interestsget.AddRange(_interestsGenesisService.AddAccount(1, 1));
        }
        catch (Exception ex)
        {

            Debug.WriteLine("API null--------------->" + ex);
        }

    }
    private List<Interests> _interests;
    public List<Interests> Interestsget
    {
        get { return _interests; }
        set { _interests = value; RaisePropertyChanged(() => Interestsget); }
    }
}

В целом, это не заполняет мою таблицу, просто пусто, нет кнопки с текстом JSON от Api. При отладке это показывает, что я получил ответ от API, который хранится в моем Interestsget, который является списком ... Единственная проблема Мне нужно сделать так, чтобы UIButton показывал текст на моем столе ... он даже не показывает кнопку, когда я устанавливаю цвет фона кнопки.

Посоветуйте, пожалуйста, с решением или рабочим проектом, который использует Tableview с пользовательским Tablesource и кнопку, которая может содержать текст из List.

Спасибо:)

...