topical media & game development

talk show tell print

#mobile-application-12-DerbyNames-MonoTouch-DerbyNames-MonoTouch-LeagueRoster.cs / cs



  using System;
  using System.Drawing;
  
  using MonoTouch.Foundation;
  using MonoTouch.UIKit;
  using System.Collections.Generic;
  
  namespace DerbyNames_MonoTouch
  {
          public partial class LeagueRoster : UIViewController
          {
                  public string TeamName { get; set; }
                  
                  public LeagueRoster () : base ("LeagueRoster", null)
                  {
                  }
                  
                  public override void ViewDidLoad ()
                  {
                          base.ViewDidLoad ();
                          UITableView tableView;
                          
                          List<DerbyName> fullRosterData = Network.GetRoster(this.TeamName);
                          List<string> data = new List<string>();
                          fullRosterData.ForEach(derbyName => data.Add(derbyName.Name));
                          
              tableView = new UITableView();
                          tableView.DataSource = new TableViewDataSource(data);
                          tableView.Frame = new RectangleF (0, 0, this.View.Frame.Width,this.View.Frame.Height);
                          
              this.View.AddSubview(tableView);
                  }
                  
                  public override void ViewDidUnload ()
                  {
                          base.ViewDidUnload ();
                          
                          ReleaseDesignerOutlets ();
                  }
                  
          private class TableViewDataSource : UITableViewDataSource
          {
              static NSString kCellIdentifier = new NSString ("DerbyName");
              private List<string> list;
  
              public TableViewDataSource (List<string> list)
              {
                  this.list = list;
              }
  
              public override int RowsInSection (UITableView tableview, int section)
              {
                  return list.Count;
              }
  
              public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
              {
                  UITableViewCell cell = tableView.DequeueReusableCell (kCellIdentifier);
                  
                                  if (cell == null)
                  {
                      cell = new UITableViewCell (
                          UITableViewCellStyle.Default,
                          kCellIdentifier);
                  }
                                  
                  cell.TextLabel.Text = list[indexPath.Row];
                  return cell;
              }
          }
                  
          }
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.