Advertisement
EENielsen

TableSource.cs

Jun 12th, 2014
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using MonoTouch.Foundation;
  5. using MonoTouch.UIKit;
  6.  
  7. namespace Tandlaegen {
  8.     public class TableSource : UITableViewSource {
  9.         List<TableItem> tableItems;
  10.         NSString cellIdentifier = new NSString("TableCell");
  11.  
  12.         UIViewController viewController;
  13.         public TableSource (UIViewController ctrl, List<TableItem> items)
  14.         {
  15.             tableItems = items;
  16.             viewController = ctrl;
  17.         }
  18.  
  19.         /// <summary>
  20.         /// Called by the TableView to determine how many cells to create for that particular section.
  21.         /// </summary>
  22.         public override int RowsInSection (UITableView tableview, int section)
  23.         {
  24.             return tableItems.Count;
  25.         }
  26.  
  27.         /// <summary>
  28.         /// Called when a row is touched
  29.         /// </summary>
  30.         public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
  31.         {
  32.             Console.WriteLine ("\n");
  33.  
  34.             //new UIAlertView("Row Selected", tableItems[indexPath.Row].Heading, null, "OK", null).Show();
  35.             tableView.DeselectRow (indexPath, true);
  36.             Console.WriteLine ("Row Selected: " + tableItems [indexPath.Row].Heading.ToString());
  37.  
  38.         }
  39.  
  40.  
  41.         /// <summary>
  42.         /// Called by the TableView to get the actual UITableViewCell to render for the particular row
  43.         /// </summary>
  44.         public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
  45.         {
  46.             // request a recycled cell to save memory
  47.             CustomCell cell = tableView.DequeueReusableCell (cellIdentifier) as CustomCell;
  48.  
  49.             cell.
  50.  
  51.             // if there are no cells to reuse, create a new one
  52.             if (cell == null) {
  53.                 cell = new CustomCell (cellIdentifier);
  54.             }
  55.  
  56.             cell.UpdateCell (tableItems[indexPath.Row].Heading
  57.                 , tableItems[indexPath.Row].SubHeading
  58.                 , UIImage.FromFile ("Images/" +tableItems[indexPath.Row].ImageName)
  59.                 , tableItems[indexPath.Row].Type);
  60.  
  61.             return cell;
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement