This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TableDetailController.cs
68 lines (54 loc) · 1.84 KB
/
TableDetailController.cs
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
/*
* This controller displays a table with rows. This controller demonstrates how to insert rows after the intial set of rows has been added and displayed.
*/
using System;
using WatchKit;
using Foundation;
namespace WatchkitExtension
{
public partial class TableDetailController : WKInterfaceController
{
string[] cityNames;
public TableDetailController ()
{
}
public override void Awake (NSObject context)
{
LoadTableData ();
}
public override void WillActivate ()
{
// This method is called when the controller is about to be visible to the wearer.
Console.WriteLine ("{0} will activate", this);
}
public override void DidDeactivate ()
{
// This method is called when the controller is no longer visible.
Console.WriteLine ("{0} did deactivate", this);
}
void LoadTableData ()
{
cityNames = new [] { "Cupertino", "Sunnyvale", "Campbell", "Morgan Hill", "Mountain View" };
interfaceTable.SetNumberOfRows (cityNames.Length, "default");
for (var i = 0; i < cityNames.Length; i++) {
var row = (TableRowController)interfaceTable.GetRowController (i);
row.RowLabel.SetText (cityNames [i]);
}
}
public override void DidSelectRow (WKInterfaceTable table, nint rowIndex)
{
var newCityNames = new [] { "Saratoga", "San Jose" };
var newCityIndexes = NSIndexSet.FromNSRange (new NSRange (rowIndex + 1, newCityNames.Length));
// Insert new rows into the table.
interfaceTable.InsertRows (newCityIndexes, "default");
// Update the rows that were just inserted with the appropriate data.
var newCityNumber = 0;
newCityIndexes.EnumerateIndexes ((nuint idx, ref bool stop) => {
var newCityName = newCityNames [newCityNumber];
var row = (TableRowController)interfaceTable.GetRowController ((nint) idx);
row.RowLabel.SetText (newCityName);
newCityNumber++;
});
}
}
}