3

I want to add a footer view to a UITableView that shows a UIProgresIndicator when the user has reached the end of the list and new data will be loaded, or a UILabel when there are no more data to be fetched.

I have used the code below, but nothing happens:

UITableViewHeaderFooterView footer = new UITableViewHeaderFooterView ();

UILabel futerlabel = new UILabel ();
futerlabel.Text = "Duke u ngarkuar";

footer.AddSubview (futerlabel);

Any way how to achieve this.

Iain Smith
  • 9,230
  • 4
  • 50
  • 61
Xhulio
  • 581
  • 7
  • 26

3 Answers3

3

If you are in a UITableViewController try this:

        TableView.TableFooterView = footer;

UPDATE

After having a think about this I would suggest not using a footer but rather an extra cell at the end of your data, this will get this effect.

Using this method to check if you have scrolled to the last item and to update the table's data:

public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
    {
        // if showing last row of last section, load more
        if (indexPath.Section == tableView.NumberOfSections()-1 && indexPath.Row == tableView.DataSource.RowsInSection(tableView, indexPath.Section)-1 && !FullyLoaded) {
            var growRowSource = tableView.DataSource as GrowRowTableDataSource;
            if (growRowSource != null) {
                FullyLoaded = growRowSource.LoadNextPage ();
                Task.Delay (5000);
                tableView.ReloadData ();    
            }

        }
    }

And then in the Delegate checking for the last item and creating a different cell like so:

public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        if (indexPath.Row == LoadedItems.Count) {
            var loadingCell = tableView.DequeueReusableCell (LoadingCellID, indexPath) as LoadFooterCell;
            loadingCell.Loading = !hasNextPage;
            return loadingCell;
        }
        var cell = tableView.DequeueReusableCell (CellID, indexPath) as GrowRowTableCell;
        var item = LoadedItems [indexPath.Row];

        // Setup
        cell.Image = UIImage.FromFile(item.ImageName);
        cell.Title = item.Title;
        cell.Description = item.Description;

        return cell;
    }
    bool hasNextPage;

I quickly mocked an example from the GrowTable Xamarin sample code here: https://github.com/b099l3/LoadingTableExample

Iain Smith
  • 9,230
  • 4
  • 50
  • 61
  • Nope, I am in a UIViewController because, I have also a SearchBar and some other UIViews. I have a UITableViewSource class and a UITableViewCell custom class – Xhulio Apr 22 '16 at 19:00
  • 1
    I have updated my answer with a solution that might suit, let me know if you have any issues. – Iain Smith Apr 23 '16 at 01:50
2

You could accomplish this in several ways, I will layout a few here:

In your TableViewSource you can do this:

1.) Implement: public override UIView GetViewForFooter(UITableView tableView, nint section) and return your UILabel

2.) Implement public override nfloat GetHeightForFooter(UITableView tableView, nint section) and return a height for your UIView


If your Footer is going to be a simple UILabel, you can replace Step 1 above with this:

Implement public override string TitleForFooter(UITableView tableView, nint section) and return "Duke u ngarkuar".

You will still need to implement public override nfloat GetHeightForFooter(UITableView tableView, nint section) and return a height otherwise your footer wont show up.


Alternatively, UITableView exposes a property called TableFooterViewthat allows you to set a UIView for a footer.

pnavk
  • 4,552
  • 2
  • 19
  • 43
0

You can size this to your liking.

var footerView = new UIView(new RectangleF(0, 0, 375, 66));
TableView.TableFooterView = footerView;
fred
  • 397
  • 1
  • 9
  • 13