Created
November 7, 2009 02:19
-
-
Save iseebi/228485 to your computer and use it in GitHub Desktop.
UITableView template for MonoTouch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
namespace EbiSoft.Sample | |
{ | |
public partial class TableViewSampleViewController : UIViewController | |
{ | |
#region Constructors | |
// The IntPtr and NSCoder constructors are required for controllers that need | |
// to be able to be created from a xib rather than from managed code | |
public TableViewSampleViewController (IntPtr handle) : base(handle) | |
{ | |
Initialize (); | |
} | |
[Export("initWithCoder:")] | |
public TableViewSampleViewController (NSCoder coder) : base(coder) | |
{ | |
Initialize (); | |
} | |
public TableViewSampleViewController () : base("TableViewSampleViewController", null) | |
{ | |
Initialize (); | |
} | |
void Initialize () | |
{ | |
} | |
#endregion | |
public override void LoadView () | |
{ | |
base.LoadView (); | |
// Setup TableView | |
tableView.DataSource = new TableViewDataSource(this); | |
tableView.Delegate = new TableViewDelegate(this); | |
} | |
#region TableView control | |
#region Delegate class | |
private class TableViewDelegate : UITableViewDelegate { | |
#region Initialize / Owner connection | |
private TableViewSampleViewController m_owner; | |
public TableViewSampleViewController Owner { | |
get { return m_owner; } | |
} | |
public TableViewDelegate (TableViewSampleViewController owner) | |
{ | |
m_owner = owner; | |
} | |
#endregion | |
public override void RowSelected (UITableView tableView, NSIndexPath indexPath) | |
{ | |
Console.WriteLine("Selected"); | |
} | |
} | |
#endregion | |
#region DataSource class | |
private class TableViewDataSource : UITableViewDataSource { | |
#region Initialize / Owner connection | |
private TableViewSampleViewController m_owner; | |
public TableViewSampleViewController Owner { | |
get { return m_owner; } | |
} | |
public TableViewDataSource (TableViewSampleViewController owner) | |
{ | |
m_owner = owner; | |
} | |
#endregion | |
#region Return counts | |
public override int NumberOfSections (UITableView tableView) | |
{ | |
return 2; | |
} | |
public override int RowsInSection (UITableView tableview, int section) | |
{ | |
return 2; | |
} | |
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) | |
{ | |
UITableViewCell cell = GetReuseCell(tableView, "main"); | |
cell.TextLabel.Text = "TEST"; | |
return cell; | |
} | |
#endregion | |
#region Control Cell reuse | |
private UITableViewCell GetReuseCell(UITableView tableView, string identifier) { | |
UITableViewCell returnValue = tableView.DequeueReusableCell(identifier); | |
if (returnValue == null) { | |
returnValue = new UITableViewCell(UITableViewCellStyle.Default, identifier); | |
} | |
return returnValue; | |
} | |
#endregion | |
} | |
#endregion | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment