may I know how to make the rows of my table can be swipe to delete or pop out a "red stop" button to allow user to delete the inserted data?
Below attached with the code of my Table ViewController cs file that only displays all data in table list :
*The view controller is created using storyboard, not by code.
using Foundation;
using System;
using UIKit;
using SQLite;
using System.Collections.Generic;
using System.IO;
namespace One
{
public partial class StudentDataBaViewController : UITableViewController
{
private string pathToDatabase;
private List<Student> students;
public StudentDataBaViewController (IntPtr handle) : base (handle)
{
students = new List<Student>();
}
//connect to student_da.db database file and create a table named Student
public override void ViewDidLoad()
{
base.ViewDidLoad();
//path of the database
var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
pathToDatabase = Path.Combine(documentsFolder, "student_db.db");
//connect database and create table
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
connection.CreateTable<Student>();
}
}
//used to relaod or update new elements entered on the list
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
students = new List<Student>();
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
var query = connection.Table<Student>();
foreach (Student student in query)
{
students.Add(student);
TableView.ReloadData();
}
}
}
public override nint RowsInSection(UITableView tableView, nint section)
{
return students.Count;
}
//make elements to be display on the database list
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell("student");
var data = students[indexPath.Row];
cell.TextLabel.Text = data.StudentName;
cell.DetailTextLabel.Text = data.StudentId;
return cell;
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
return true;
}
}
public class Student
{
[PrimaryKey]
public string StudentId
{
get;
set;
}
public string StudentName
{
get;
set;
}
public string StudentPassword
{
get;
set;
}
public bool StudentAttendence
{
get;
set;
}
}
}
Add the following methods
public override void CommitEditingStyle (UITableView tableView,UITableViewCellEditingStyle editingStyle, Foundation.NSIndexPath indexPath){
switch (editingStyle) {
case UITableViewCellEditingStyle.Delete:
// remove the item from the underlying data source
tableItems.RemoveAt(indexPath.Row);
// delete the row from the table
tableView.DeleteRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
break;
case UITableViewCellEditingStyle.None:
Console.WriteLine ("CommitEditingStyle:None called");
break;
}}
In addition to overriding the getcell method , you need to provide CommitEditingStyle
public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, MonoTouch.Foundation.NSIndexPath indexPath)
{
switch (editingStyle) {
case UITableViewCellEditingStyle.Delete:
// remove the item from the underlying data source
tableItems.RemoveAt(indexPath.Row);
// delete the row from the table
tableView.DeleteRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
break;
default:
break;
}
}
Related
i would like to make a verification on/off button to show is the student verified. Once the switch is turn on in the "AddStudentViewController", a checkmark will show at the right hand side of the specific student's row in the table list in "StudentDataBaViewController". May i know how to do that?
**Additional Information:
1)StudentDataBaViewContoller (1st page of the app) is a TableViewController
2)AddStudentViewController (2nd page of the app) is a normal View Controller
Both are connected with a Push Segue named "StuSegue"
Below attached the code of my 2 view controller:
Code for "StudentDataBaViewController":
using Foundation;
using System;
using UIKit;
using SQLite;
using System.Collections.Generic;
using System.IO;
namespace One
{
public partial class StudentDataBaViewController : UITableViewController
{
private string pathToDatabase;
private List<Student> students;
public StudentDataBaViewController (IntPtr handle) : base (handle)
{
students = new List<Student>();
}
/*public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
if (segue.Identifier == "StuSegue")
{ // set in Storyboard
var navctlr = segue.DestinationViewController as AddStudentViewController;
if (navctlr != null)
{
var source = TableView.Source as StudentDataBaViewController;
var rowPath = TableView.IndexPathForSelectedRow;
var item = source.GetItem(rowPath.Row);
navctlr.SetTask(this, item); // to be defined on the TaskDetailViewController
}
}
}
*/
//connect to student_da.db database file and create a table named Student
public override void ViewDidLoad()
{
base.ViewDidLoad();
//path of the database
var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
pathToDatabase = Path.Combine(documentsFolder, "student_db.db");
//connect database and create table
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
connection.CreateTable<Student>();
}
}
//used to relaod or update new elements entered on the list
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
students = new List<Student>();
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
var query = connection.Table<Student>();
foreach (Student student in query)
{
students.Add(student);
TableView.ReloadData();
}
}
}
public override nint RowsInSection(UITableView tableView, nint section)
{
return students.Count;
}
//make elements to be display on the database list
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell("student");
var data = students[indexPath.Row];
cell.TextLabel.Text = data.StudentName;
cell.DetailTextLabel.Text = data.StudentId;
return cell;
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
return true;
}
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, Foundation.NSIndexPath indexPath)
{
switch (editingStyle)
{
case UITableViewCellEditingStyle.Delete:
// remove the item from the underlying data source
students.RemoveAt(indexPath.Row);
// delete the row from the table
tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
break;
case UITableViewCellEditingStyle.None:
Console.WriteLine("CommitEditingStyle:None called");
break;
}
}
}
public class Student
{
[PrimaryKey]
public string StudentId
{
get;
set;
}
public string StudentName
{
get;
set;
}
public string StudentPassword
{
get;
set;
}
public bool StudentAttendence
{
get;
set;
}
}
}
Code for "AddStudentViewController":
using Foundation;
using System;
using System.IO;
using UIKit;
namespace One
{
public partial class AddStudentViewController : UIViewController
{
private string pathToDatabase;
//used to access same database to grab data for display
protected AddStudentViewController (IntPtr handle) : base (handle)
{
// Note: this .ctor should not contain any initialization logic.
var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
pathToDatabase = Path.Combine(documentsFolder, "student_db.db");
}
// create a function for save button
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
saveStudent.Clicked += SaveButton_Clicked;
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
//create connection with database and make handler for save button and insert the element into database
void SaveButton_Clicked(object sender, EventArgs e)
{
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
connection.Insert(new Student() { StudentName = AddStuNameTxt.Text, StudentId = AddStuIdTxt.Text, StudentPassword = AddStuPassTxt.Text, StudentAttendence =true });
new UIAlertView("Updated !", "Student successfully created", null, "OK", null).Show();
}
//navigate page back to database list
NavigationController.PopToRootViewController(true);
}
}
}
According to my understanding, you are hoping refushing the UI in "StudentDataBaViewController" after the switch is turn on in the "AddStudentViewController".
you can use delegate to send message between two controllers.
I am writing a Xamarin.iOS application with MvvmCross. I am trying to make a table, I can see the items being binded into the source, but I never see any cells being created. The function GetOrCreateCellFor never gets called. Here is my code:
public class ContactsManager
{
ContactsView _contactsView;
public ContactsManager()
{
_contactsView = new ContactsView();
Source = new FriendTableViewSource(_contactsView.FriendsTableView);
_contactsView.FriendsTableView.Source = Source;
}
public FriendTableViewSource Source { get; set; }
}
public class FriendTableViewSource : MvxTableViewSource
{
private readonly List<SeeMyFriendsItemViewModel> _content = new List<SeeMyFriendsItemViewModel>();
private readonly UITableView _tableView;
public FriendTableViewSource(UITableView t) : base(t)
{
_tableView = t;
t.RegisterNibForCellReuse(UINib.FromName(FriendCell.Key, NSBundle.MainBundle), FriendCell.Key);
}
private void Init(IEnumerable<SeeMyFriendsItemViewModel> items)
{
_content.Clear();
_content.AddRange(items);
}
public override System.Collections.IEnumerable ItemsSource
{
get
{
return base.ItemsSource;
}
set
{
// I put a break point here to check if I'm getting the items, and it is, so the binding is fine...
if (value != null)
Init(value.Cast<SeeMyFriendsItemViewModel>());
base.ItemsSource = value;
_tableView.ReloadData();
}
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return 60;
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
// This function never gets called!
return TableView.DequeueReusableCell(FriendCell.Key, indexPath);
}
}
[Register("FriendCell")]
public class FriendCell : MvxTableViewCell
{
public static readonly NSString Key = new NSString("FriendCell");
public static readonly UINib Nib;
static FriendCell()
{
Nib = UINib.FromName("FriendCell", NSBundle.MainBundle);
}
protected FriendCell(IntPtr handle) : base(handle)
{
BackgroundColor = UIColor.Red;
}
}
EDIT
This is what a working version of your source should look like. What's also interesting is that GetOrCreateCellFor won't get called if the table is not added to your view.
public class FriendTableViewSource : MvxTableViewSource
{
private readonly List<SeeMyFriendsItemViewModel> _content = new List<SeeMyFriendsItemViewModel>();
private MvxNotifyCollectionChangedEventSubscription _subscription;
public FriendTableViewSource(UITableView t) : base(t)
{
t.RegisterClassForCellReuse(typeof(FriendCell), FriendCell.Key);
}
private void Init(IEnumerable<SeeMyFriendsItemViewModel> items)
{
_content.Clear();
_content.AddRange(items);
}
public override System.Collections.IEnumerable ItemsSource
{
get
{
return base.ItemsSource;
}
set
{
if (value != null)
{
Init(value.Cast<SeeMyFriendsItemViewModel>());
var collectionChanged = value as System.Collections.Specialized.INotifyCollectionChanged;
if (collectionChanged != null)
{
_subscription = collectionChanged.WeakSubscribe(CollectionChangedOnCollectionChanged);
}
}
base.ItemsSource = value;
ReloadTableData();
}
}
protected override void CollectionChangedOnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
{
if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
foreach (var item in args.NewItems)
{
var chatItem = item as SeeMyFriendsItemViewModel;
_content.Add(chatItem);
}
}
Init(ItemsSource.Cast<SeeMyFriendsItemViewModel>());
base.CollectionChangedOnCollectionChanged(sender, args);
InvokeOnMainThread(() => {
ReloadTableData();
TableView.SetContentOffset(new CGPoint(0, TableView.ContentSize.Height - TableView.Frame.Size.Height), true);
});
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return 60;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return _content.Count();
}
public override nint NumberOfSections(UITableView tableView)
{
return 1;
}
protected override object GetItemAt(NSIndexPath indexPath)
{
if (indexPath.Row < _content.Count)
return _content[indexPath.Row];
return null;
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
return TableView.DequeueReusableCell(FriendCell.Key, indexPath);
}
}
Override RowsInSection in FriendTableViewSource .
Since tableview needs row count and row height to decide its frame, if height = 0 or count = 0, GetOrCreateCellFor will never be called.
I am using MvvmCross for my Xamarin iOS project. For my tableview source I have say, a,b,c,d,e,f,g,h records and section(header): 0 of suitable view has 3 records and section: 1 had 4 then
Expected result
Section-0
a
b
c
Section-1
d
e
f
g
I'm getting:
Section-0
a
b
c
Section-1
a
b
c
d
The records are being duplicated. I checked the source but source has correct data.
ISSUE:
At the end of each section the source is restarting from the top again to fill the records
My source:
View:
base.DoBind();
var source = new TableSource<string> (Table, ViewModel);
Table.Source = source;
Table.ReloadData();
Table.AlwaysBounceVertical = false;
var set = this.CreateBindingSet<View, ViewModel>();
set.Bind(source).To(vm => vm.CardsList);
set.Apply();
Cell:
protected override void DoBind()
{
var set = this.CreateBindingSet<Cell, ListViewModel>();
set.Bind(LblNum).To(vm => vm.CardNumber);
set.Bind(Balance).To(vm => vm.Balance);
set.Apply();
}
CellViewModel
public class ListViewModel : MvxViewModel
{
private string _CardNumber;
public string Number
{
get { return _Number); }
set { _CardNumber = value; }
}
private string _Balance;
public string Balance
{
get { _Balance; }
set { _Balance = value; }
}
Can anyone please advice how to resolve this
Update
UITableView _tableView;
public TableSource(UITableView tableView, object item) : base(tableView)
{
this.viewModel = item as ViewModel;
this._tableView = tableView;
tableView.RegisterNibForCellReuse(HeaderCell.Nib, HeaderCell.Key); tableView.RegisterNibForCellReuse(UINib.FromName(Cell.Key, NSBundle.MainBundle), Cell.Key);
tableView.RegisterNibForHeaderFooterViewReuse(UINib.FromName(HeaderCell.Key, NSBundle.MainBundle), HeaderCell.Key);
tableView.ReloadData();
var DataDic = new Dictionary<string, List<string>>
{
{ "section1", new List<string> {}},
{ "section2", new List<string> {}},
{ "section3", new List<string> {}}
};
//create the data
var list = new List<TableModel<string>>();
foreach (var section in DataDic)
{
var sectionData = new TableModel<string>()
{
Title = section.Key
};
foreach (var row in section.Value)
{
sectionData.Add(row);
}
list.Add(sectionData);
}
TableItems = list;
}
public override nint NumberOfSections(UITableView tableView)
{
return TableItems.Count;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
int result = 0;
if (section == 0)
{
result = viewModel.NumOfGiftCards;
}
else if (section == 1)
{
result = viewModel.NumOfRewardsCerts;
}
return result;
}
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
return section == 2 ? 0f : 74f;
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return indexPath.Section == 2 ? 95f : 62f;
}
public override IEnumerable ItemsSource
{
get
{
return base.ItemsSource;
}
set
{
base.ItemsSource = value;
_tableView.ReloadData();
}
}
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
var header = tableView.DequeueReusableHeaderFooterView(HeaderCell.Key) as HeaderCell;
return header;
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
var cell = tableView.DequeueReusableCell(Cell.Key, indexPath) as Cell;
return cell;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
viewModel.CardDetailsCommand.Execute(null);
}
I don't think the ItemSource you are binding the CardsList to is not matching up to the TableItems, viewModel.NumOfRewardsCerts or viewModel.NumOfGiftCards that you are using the table source.
Have you had a looked at the MvxExpandableItemSource (the sample is here) It can handle 2 dimensional ItemSources:
private IEnumerable<TItemSource> _itemsSource;
public new IEnumerable<TItemSource> ItemsSource
{
get
{
return _itemsSource;
}
set
{
_itemsSource = value;
_sectionExpandableController.ResetState();
ReloadTableData();
}
}
It deals with expanding and collapsing the from the headers, see below, but you could disable that functionality and force them to be expanded all the time:
I am trying to bind grouped data to a table, but when I run the code the binding seems to be trying to create a cell for the Section level items rather than creating a section with the cells behind it.
First, I create my table:
table = new UITableView(CGRect.Empty, UITableViewStyle.Grouped);
table.RowHeight = UxConstants.UiDimensions.Dimension48;
table.AutoresizingMask = UIViewAutoresizing.All;
table.ScrollEnabled = true;
then I create my view source and bind it:
var source = new OperationalInfoTableViewSource(table);
table.Source = source;
var set = this.CreateBindingSet<IncidentInformationView, IncidentInformationViewModel>();
set.Bind(source).For(vm => vm.ItemsSource).To(vm => vm.TableSourceItem);
set.Apply();
I'm using a simplified class at the moment; so the binding target (TableSourceItem) is currently defined as:
public ObservableCollection<Stuff> TableSourceItem
{
get
{
return tableSourceItem;
}
set
{
tableSourceItem = value;
RaisePropertyChanged(() => TableSourceItem);
}
}
and the 'Stuff' class is simply
public class Stuff
{
public string Title {
get;
set;
}
public List<string> Items {
get;
set;
}
}
When I declare my data :
var items = new List<Stuff>();
items.Add(new Stuff { Title = "Group 1", Items = new List<string> { "Item 1", "Item 2" } });
items.Add(new Stuff { Title = "Group 2", Items = new List<string> { "Item 4", "Item 5"} });
TableSourceItem = new ObservableCollection<Stuff>(items);
The final bit of Code, is the table view source I have defined. This inherits from the MvxStandardTableView source:
public class OperationalInfoTableViewSource : MvxStandardTableViewSource
{
List<Stuff> items;
public OperationalInfoTableViewSource(UITableView tableView) : base (tableView)
{
TableView.RegisterClassForCellReuse (typeof(OperationalInfoViewCell), OperationalInfoViewCell.Key);
}
public override System.Collections.IEnumerable ItemsSource
{
get
{
return items;
}
set
{
if (value != null)
{
items = new List<Stuff>();
foreach (Stuff item in value)
{
items.Add(item);
}
base.ItemsSource = items;
}
}
}
public override string TitleForHeader(UITableView tableView, nint section)
{
return "Header";
}
public override nint NumberOfSections(UITableView tableView)
{
var i = items == null ? 0 : items.Count();
Mvx.Trace(String.Format( "Number of Sections {0}", i ));
return i;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return items == null ? 0 : items[(int)section].Items.Count();
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
return false;
}
public override bool CanPerformAction(UITableView tableView, ObjCRuntime.Selector action, NSIndexPath indexPath, NSObject sender)
{
return false;
}
public override bool CanMoveRow(UITableView tableView, NSIndexPath indexPath)
{
return false;
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
var cell = tableView.DequeueReusableCell(OperationalInfoViewCell.Key);
return cell;
}
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
return UxConstants.UiDimensions.Dimension32;
}
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
var operationalInfoTitle = new UILabel()
{
Lines = 1,
Font = UxConstants.UxFonts.MediumBold,
TextColor = UxConstants.UxColours.BBlue,
Text = "Guidance & Info"
};
var operationalInfoTitleDivider = new UIView()
{
BackgroundColor = UxConstants.UxColours.MGrey
};
var operationalInfoListView = new UIView();
operationalInfoListView.AddSubviews(operationalInfoTitle, operationalInfoTitleDivider);
operationalInfoListView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
operationalInfoListView.AddConstraints(operationalInfoTitle.FullWidthOf(operationalInfoListView, UxConstants.UiDimensions.Dimension16));
operationalInfoListView.AddConstraints(operationalInfoTitleDivider.FullWidthOf(operationalInfoListView, UxConstants.UiDimensions.Dimension16));
operationalInfoListView.AddConstraints(
operationalInfoTitle.Height().EqualTo(UxConstants.UiDimensions.Dimension32),
operationalInfoTitle.AtTopOf(operationalInfoListView),
operationalInfoTitleDivider.Below(operationalInfoTitle),
operationalInfoTitleDivider.Height().EqualTo(2));
return operationalInfoListView;
}
}
I would expect 2 sections, each with two cells, but its seems to be creating one cell per Stuff class rather than one section per Stuff class.
Any ideas?
Found out the issue, I have failed to implement the important override:
protected override object GetItemAt(NSIndexPath indexPath)
{
if (items == null)
{
return null;
}
return items[indexPath.Section].Items.ElementAt((int)indexPath.Item);
}
Once I had included this method override it worked fine!
I have been trying to implement a multi column table view by combining multiple UITableViews.
One problem I have run into, is that I am unable to get the override of RowSelected to be called when I select a row on one of the TableViews in my multi column view.
When running in the simulator, It highlights a row when clicked, so the ability to click a row is working, however the override is not called.
Below is the code for the UITableViewSource. Under that is the code that sets up the multi column view.
Any help would be greatly appreciated.
public class TableSource : UITableViewSource
{
protected List<object> _tableItems;
protected string cellIdentifier = "TableCell";
private string _propertyName;
public TableSource (List<object> items, string propertyName)
{
_tableItems = items;
_propertyName = propertyName;
}
public override int RowsInSection (UITableView tableview, int section)
{
return _tableItems.Count;
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
// request a recycled cell to save memory
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
// if there are no cells to reuse, create a new one
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
PropertyInfo property = _tableItems [indexPath.Row].GetType ().GetProperty (_propertyName);
cell.TextLabel.Text = property.GetValue(_tableItems[indexPath.Row]).ToString();
cell.UserInteractionEnabled = true;
return cell;
}
public override UIView GetViewForHeader (UITableView tableView, int section)
{
// NOTE: Don't call the base implementation on a Model class
// see http://docs.xamarin.com/guides/ios/application_fundamentals/delegates,_protocols,_and_events
throw new NotImplementedException ();
}
public override void RowDeselected (UITableView tableView, NSIndexPath indexPath)
{
// NOTE: Don't call the base implementation on a Model class
// see http://docs.xamarin.com/guides/ios/application_fundamentals/delegates,_protocols,_and_events
throw new NotImplementedException ();
}
public override void RowHighlighted (UITableView tableView, NSIndexPath rowIndexPath)
{
// NOTE: Don't call the base implementation on a Model class
// see http://docs.xamarin.com/guides/ios/application_fundamentals/delegates,_protocols,_and_events
throw new NotImplementedException ();
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView("Row Selected", "", null, "OK", null).Show();
tableView.DeselectRow (indexPath, true);
}
}
[Register("MultiColumnTableView")]
public class MultiColumnTableView: UIView
{
List<SingleColumnView> _tableViews;
IEnumerable<object> _dataSource;
SingleColumnView scrollingTable = null;
int _nextColumnX;
public MultiColumnTableView(){
}
public MultiColumnTableView (IntPtr handle):base(handle)
{
}
public IEnumerable<object> DataSource
{
get
{
return _dataSource;
}
set
{
_dataSource = value;
}
}
public void AddColumn(string columnName, string propertyName, int width)
{
if(_tableViews== null)
_tableViews = new List<SingleColumnView>();
var newColumn = new SingleColumnView (columnName, propertyName, _dataSource, width, _nextColumnX);
this.AddSubview (newColumn);
_tableViews.Add (newColumn);
_nextColumnX += (width);
newColumn.Scrolled += Scrolled;
foreach(var table in _tableViews)
{
table.ShowsVerticalScrollIndicator = false;
}
_tableViews.Last ().ShowsVerticalScrollIndicator = true;
}
public void AddColumn(string columnName, string[] propertyNames, string format)
{
if(_tableViews== null)
_tableViews = new List<SingleColumnView>();
var column = new SingleColumnView (columnName, propertyNames, format, _dataSource);
_tableViews.Add (column);
column.Scrolled += Scrolled;
foreach(var table in _tableViews)
{
table.ShowsVerticalScrollIndicator = false;
table.AllowsSelection = true;
}
_tableViews.Last ().ShowsVerticalScrollIndicator = true;
}
private void Scrolled (object sender, EventArgs args)
{
if (scrollingTable == null) {
scrollingTable = sender as SingleColumnView;
}
if(scrollingTable != _tableViews.Last())
_tableViews.Last().FlashScrollIndicators();
foreach (var table in _tableViews) {
if (table != sender) {
table.ContentOffset = (sender as SingleColumnView).ContentOffset;
}
}
scrollingTable = null;
}
}
public class SingleColumnView: UITableView
{
public IEnumerable<object> _dataSource;
public string _propertyName;
public string[] _propertyNames;
public string _format;
public string _columnName;
public SingleColumnView(string columnName, string propertyName, IEnumerable<object> dataSource, int width, int offsetX):base(new RectangleF(offsetX,0,width,500))
{
_columnName = columnName;
_propertyName = propertyName;
_dataSource = dataSource;
this.Source = new TableSource (dataSource.ToList(), propertyName);
//this.BackgroundColor = new UIColor(new MonoTouch.CoreGraphics.CGColor(255,0,0));
//this.SeparatorStyle = UITableViewCellSeparatorStyle.None;
this.SeparatorInset = UIEdgeInsets.Zero;
}
public SingleColumnView(string columnName, string[] propertyNames, string format, IEnumerable<object> dataSource):base()
{
_columnName = columnName;
_propertyNames = propertyNames;
_format = format;
_dataSource = dataSource;
}
}
How are you implementing the custom UITableViewDelegate? I would suggest using Monotouch's UITableViewSource as it combines both the UITableViewDataSource and the UITableViewDelegate into one file which makes things so much easier.
Source:more details
Add to You project
I think you should try using WeakDelegate to make this work.