Trying to fill a UITableView with UIProgressViews

RyanKellerRyanKeller USMember

This is my code:

`using Foundation;
using System;
using System.Collections.Generic;
using UIKit;

namespace Insite_FLX
{
public partial class ResultTableView : UITableViewController
{
private List items;
public ResultTableView(IntPtr handle) : base(handle)
{
Initialize();
}

    public ResultTableView(string[] items)
    {
        Initialize();
    }

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

        var datasource = new TableSource(items, this);
        table.Source = datasource;
    }

    private void Initialize()
    {
        items = new List<UIProgressView>
        {
        };
        //this fills the items list to show in the table
        for (int i = 1; i < 101; i++)
        {
            UIProgressView progress = new UIProgressView();
            progress.SetProgress(25, true);
            progress.SizeToFit();
            progress.BackgroundColor = UIColor.Blue;
            items.Add(progress);
        };


        Console.WriteLine(items);
    }

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
    }

    private class TableSource : UITableViewSource
    {
        List<UIProgressView> TableItems = new List<UIProgressView>();
        List<UIProgressView> searchItems = new List<UIProgressView>();
        private ResultTableView View;
        string CellIdentifier = "TableCell";

        public TableSource(List<UIProgressView> items, ResultTableView View)
        {
            this.TableItems = items;
            this.searchItems = items;
            this.View = View;
        }

        public override nint RowsInSection(UITableView tableview, nint section)
        {
            return searchItems.Count;
        }

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
            UIProgressView item = TableItems[indexPath.Row];

            //---- if there are no cells to reuse, create a new one
            if (cell == null)
            { cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); }

            //cell.TextLabel.Text = searchItems[indexPath.Row].Name;
            return cell;
        }

        public override nint NumberOfSections(UITableView tableView)
        {
            return 1;
        }

        public void PerformSearch(string searchText)
        {
            //searchText = searchText.ToLower();
            //this.searchItems = TableItems.Where(x => x.Name.ToLower().Contains(searchText)).ToList();
        }

        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            UIViewController newController = new UIViewController();
            newController.Title = "Batches";
            View.NavigationController.PushViewController(newController, true);

        }
    }
}

}`

I can see that the table is filling with 100 progress views, however, they are not showing up in my table...

Any help would be greatly appreciated!
Thanks!

Answers

Sign In or Register to comment.