int UpdateData(int count) { TKDataSourceGroup group = (TKDataSourceGroup)this.dataSource.Items [0]; long startIndex = this.data.Count; int i = 0; for (; i < count; i++) { if (i + startIndex >= group.Items.Length) { return(i); } Random r = new Random(); int points = r.Next(0, 101); this.data.Insert(0, string.Format("{0}: {1} points", group.Items [i + startIndex], points)); } return(i); }
public override void ViewDidLoad() { base.ViewDidLoad(); this.dataSource.LoadDataFromJSONResource("ListViewSampleData", "json", "teams"); this.dataSource.GroupItemSourceKey = "items"; this.dataSource.GroupWithKey("key"); TKListView listView = new TKListView(this.View.Bounds); listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; listView.WeakDataSource = dataSource; listView.SelectionBehavior = TKListViewSelectionBehavior.Press; this.View.AddSubview(listView); TKListViewColumnsLayout layout = (TKListViewColumnsLayout)listView.Layout; layout.CellAlignment = TKListViewCellAlignment.Stretch; layout.ItemSize = new CGSize(300, 44); layout.MinimumLineSpacing = 0; layout.HeaderReferenceSize = new CGSize(100, 44); layout.FooterReferenceSize = new CGSize(100, 44); this.dataSource.Settings.ListView.InitCell(delegate(TKListView list, NSIndexPath indexPath, TKListViewCell cell, NSObject item) { TKDataSourceGroup group = this.dataSource.Items[indexPath.Section] as TKDataSourceGroup; cell.TextLabel.Text = group.Items[indexPath.Row] as NSString; }); this.dataSource.Settings.ListView.InitHeader(delegate(TKListView list, NSIndexPath indexPath, TKListViewHeaderCell headerCell, TKDataSourceGroup group) { headerCell.TextLabel.Text = String.Format("{0}", group.Key); headerCell.TextLabel.TextAlignment = UITextAlignment.Center; }); this.dataSource.Settings.ListView.InitFooter(delegate(TKListView list, NSIndexPath indexPath, TKListViewFooterCell footerCell, TKDataSourceGroup group) { footerCell.TextLabel.Text = String.Format("Members count: {0}", group.Items.Length); footerCell.TextLabel.TextAlignment = UITextAlignment.Left; footerCell.TextLabel.Frame = new CGRect(5, 10, 200, 22); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); dataSource = new TKDataSource(ArrayWithObjects(new object [] { 10, 5, 12, 7, 44 }), null); // filter all values less or equal to 3 dataSource.Filter((NSObject item) => { return(((NSNumber)item).NIntValue > 5); }); // sort ascending dataSource.Sort((NSObject obj1, NSObject obj2) => { nint a = ((NSNumber)obj1).NIntValue; nint b = ((NSNumber)obj2).NIntValue; if (a < b) { return(NSComparisonResult.Descending); } else if (a > b) { return(NSComparisonResult.Ascending); } return(NSComparisonResult.Same); }); // group odd/even values dataSource.Group((NSObject item) => { return(NSObject.FromObject(((NSNumber)item).NIntValue % 2 == 0)); }); // multiply every value * 10 dataSource.Map((NSObject item) => { return(NSObject.FromObject(((NSNumber)item).NIntValue * 10)); }); // find the max value NSObject maxValue = dataSource.Reduce(NSObject.FromObject(0), (NSObject item, NSObject value) => { if (((NSNumber)item).NIntValue > ((NSNumber)value).NIntValue) { return(item); } return(value); }); Console.WriteLine("the max value is: {0}", ((NSNumber)maxValue).NIntValue); // output everything to the console dataSource.Enumerate((NSObject item) => { if (item.IsKindOfClass(new ObjCRuntime.Class(typeof(TKDataSourceGroup)))) { TKDataSourceGroup group = (TKDataSourceGroup)item; Console.WriteLine("group: {0}", group.Key); } else { Console.WriteLine("{0}", ((NSNumber)item).NIntValue); } }); // bind with a table view var tableView = new UITableView(this.View.Bounds); tableView.DataSource = dataSource; this.View.AddSubview(tableView); }