First of all I suggest to rewrite the TodayEmails
method:
public List<EmailItem> TodayEmails(List<EmailItem> emailArray)
{
foreach(var emailItem in emailArray)
{
if(emailItem.RecievedDate.Date == DateTime.Today.Date)
{
yield return emailItem;
}
}
}
Then rewrite the contructor of table source:
private List<EmailItem> _emailItems;
public TableSource (List<EmailItem> emailItems)
{
_emailItems= emailItems;
}
You should override NumberOfSections
to set the num of sections
public override int NumberOfSections(UITableView tableView)
{
return 3;
}
Then in method RowsInSection
you should return the needed num of rows for each section, so:
public override int RowsInSection(UITableView tableview, int section)
{
if(section == 0)
{
return TodayEmails(_emailItems).Count; //I don't know where your TodayEmails located, so added just the name of it
}
else if(section == 1)
{
return YesterdayEmails(_emailItems).Count; // The same as for TodayEmails
}
else
{
return OtherEmails(_emailItems).Count; // The same as for TodayEmails
}
}
And finally in GetCell
method you should return the needed cell for the section:
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
if(indexPath.Section == 0)
{
cell.TextLabel.Text = TodayEmails(_emailItems)[indexPath.Row].Subject;
}
else if(indexPath.Section == 1)
{
cell.TextLabel.Text = YesterdayEmails(_emailItems)[indexPath.Row].Subject;
}
else
{
cell.TextLabel.Text = OtherEmails(_emailItems)[indexPath.Row].Subject;
}
return cell;
}