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 fullLeagueData = Network.GetLeaugeData(); List data = new List(); 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 list; public TableViewDelegate(List 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 list; public TableViewDataSource (List 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; } } } }