topical media & game development
#mobile-application-12-DerbyNames-MonoTouch-DerbyNames-MonoTouch-LeaguesController.cs / cs
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Collections.Generic;
namespace DerbyNames_MonoTouch
{
public partial class LeaguesController : UIViewController
{
public LeaguesController () : base ("LeaguesController", null)
{
Title = NSBundle.MainBundle.LocalizedString ("Team Names", "Team Names");
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
UITableView tableView;
List<League> fullLeagueData = Network.GetLeaugeData();
List<string> data = new List<string>();
fullLeagueData.ForEach(leagueName => data.Add(leagueName.LeagueName));
tableView = new UITableView();
tableView.Delegate = new TableViewDelegate(data,this);
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 TableViewDelegate : UITableViewDelegate
{
LeaguesController leagueController;
private List<string> list;
public TableViewDelegate(List<string> list, LeaguesController controller)
{
this.leagueController = controller;
this.list = list;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
//leagueController.TabBarController.PerformSegue("LeagueRoster");
LeagueRoster roster = new LeagueRoster();
roster.TeamName = list[indexPath.Row];
// this.n
// UINavigationController navController = new UINavigationController();
leagueController.NavigationController.PushViewController(roster,true);
//UITableViewController nextController = new LeagueRoster();
//LeagueRoster controller = new LeagueRoster();
//NavigationController.PushViewController(controller,true);
//Console.WriteLine("TableViewDelegate.RowSelected: Label={0}",list[indexPath.Row]);
}
}
private class TableViewDataSource : UITableViewDataSource
{
static NSString kCellIdentifier = new NSString ("LeagueName");
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.