Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to Manage Sections in GetCell?

$
0
0

Hi,

I have a TableView that needs to display 2 sections (5 rows each), and one array of values (10 elements).

In GetCell it displays the first 5 values in the array twice, so the data related to the second section is never displayed.

Here's the full code:

public class PeriodicCertInspTableViewSource : UITableViewSource
    {
        string[] _periodicCertInspLabel, _periodicCertInspValue;

        public PeriodicCertInspTableViewSource(vw_ClientsItems clientsItem)
        {
            _periodicCertInspLabel = new string[] {
                StringLiterals.ItemSummary.UserInterfaceItems.label_periodicCertRequired,
                StringLiterals.ItemSummary.UserInterfaceItems.label_lastCertDate,
                StringLiterals.ItemSummary.UserInterfaceItems.label_lastCertStatus,
                StringLiterals.ItemSummary.UserInterfaceItems.label_certInterval,
                StringLiterals.ItemSummary.UserInterfaceItems.label_nextCertDate,
                StringLiterals.ItemSummary.UserInterfaceItems.label_periodicInspRequired,
                StringLiterals.ItemSummary.UserInterfaceItems.label_lastInspDate,
                StringLiterals.ItemSummary.UserInterfaceItems.label_lastInspStatus,
                StringLiterals.ItemSummary.UserInterfaceItems.label_inspInterval,
                StringLiterals.ItemSummary.UserInterfaceItems.label_nextInspDate,
            };

            _periodicCertInspValue = new string[] {
                IC_Tools.GetStringValue(clientsItem.PeriodicCertRequired),
                IC_Tools.FormatDate(clientsItem.LastCertDate),
                IC_Tools.GetStringValue(clientsItem.CertStatus),
                IC_Tools.GetStringValue(clientsItem.CertInterval),
                IC_Tools.FormatDate(clientsItem.NextCertDate),
                IC_Tools.GetStringValue(clientsItem.PeriodicInspectionRequired),
                IC_Tools.FormatDate(clientsItem.LastInspectionDate),
                IC_Tools.GetStringValue(clientsItem.InspectionStatus),
                IC_Tools.GetStringValue(clientsItem.InspectionInterval),
                IC_Tools.FormatDate(clientsItem.NextInspectionDate),
            };
        }

        public override int NumberOfSections(UITableView tableView)
        {
            //return the actual number of sections
            return 2;
        }

        public override int RowsInSection(UITableView tableview, int section)
        {
            //return the actual number of items in the section
            return 5;
        }

        public override string TitleForHeader(UITableView tableView, int section)
        {
            string title = string.Empty;
            if (section == 0)
                title = StringLiterals.ItemSummary.UserInterfaceItems.label_periodicCert;
            else
                title = StringLiterals.ItemSummary.UserInterfaceItems.label_periodicInsp;

            return title;
        }

        public override string TitleForFooter(UITableView tableView, int section)
        {
            string title = string.Empty;
            if (section == 0)
                title = " ";
            else
                title = " ";

            return title;
        }

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.DequeueReusableCell(StandardTableViewCell.Key) as StandardTableViewCell;
            if (cell == null)
                cell = new StandardTableViewCell(UITableViewCellStyle.Value1);

            //populate the cell with the appropriate data based on the indexPath
            cell.TextLabel.Text = _periodicCertInspLabel[indexPath.Row];
            cell.DetailTextLabel.Text = _periodicCertInspValue[indexPath.Row];

            return cell;
        }
    }

In GetCell I would just like to know which section I am dealing with, because indexPath.Row is always between 0 and 4 (because I set 5 rows per section).

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>