forked from anaisbetts/ModernHttpClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableViewRocks.cs
More file actions
92 lines (74 loc) · 2.1 KB
/
TableViewRocks.cs
File metadata and controls
92 lines (74 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
namespace HttpClient
{
class StringDataSource : UITableViewDataSource {
static NSString kDefaultCell_ID = new NSString ("f");
string [] source;
UITableView tableView;
public StringDataSource (UITableView tableView, string [] source)
{
this.source = source;
this.tableView = tableView;
}
public string [] Source {
get {
return source;
}
set {
source = value;
tableView.ReloadData ();
}
}
public override int NumberOfSections (UITableView tableView)
{
return 1;
}
public override int RowsInSection (UITableView tableView, int section)
{
return source.Length;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell (kDefaultCell_ID);
if (cell == null){
cell = new UITableViewCell (UITableViewCellStyle.Default, kDefaultCell_ID){
SelectionStyle = UITableViewCellSelectionStyle.Blue,
};
cell.IndentationWidth = 30f;
}
cell.TextLabel.Text = source [indexPath.Row];
return cell;
}
}
public class StringDelegate : UITableViewDelegate {
internal int selected;
public StringDelegate ()
{
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
tableView.CellAt (NSIndexPath.FromRowSection (selected, 0)).Accessory = UITableViewCellAccessory.None;
selected = indexPath.Row;
tableView.CellAt (indexPath).Accessory = UITableViewCellAccessory.Checkmark;
tableView.DeselectRow (indexPath, true);
}
}
public static class TableViewSelector
{
public static void Configure (UITableView tableView, string [] choices)
{
tableView.DataSource = new StringDataSource (tableView, choices);
tableView.Delegate = new StringDelegate ();
tableView.SelectRow (NSIndexPath.FromRowSection (0, 0), true, UITableViewScrollPosition.None);
}
public static int SelectedRow (this UITableView tableView)
{
var d = tableView.Delegate as StringDelegate;
if (d == null)
return 0;
return d.selected;
}
}
}