-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMapLocationViewController.cs
More file actions
127 lines (108 loc) · 4.13 KB
/
MapLocationViewController.cs
File metadata and controls
127 lines (108 loc) · 4.13 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.IO;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreLocation;
namespace Monospace2
{
public class MapLocation
{
public string Title {get;set;}
public CLLocationCoordinate2D Location {get;set;}
}
public class MapLocationViewController : UITableViewController
{
private UITableView tableView;
private UINavigationBar navBar;
private List<MapLocation> _locations;
public MapFlipViewController FlipController = null;
public MapLocationViewController (MapFlipViewController mfvc) : base()
{
FlipController = mfvc;
_locations = new List<MapLocation>();
_locations.Add(new MapLocation{Title="Monospace", Location=new CLLocationCoordinate2D(30.262251,-97.740537)});
_locations.Add(new MapLocation{Title="Your location", Location=new CLLocationCoordinate2D(0,0)});
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// no XIB !
navBar = new UINavigationBar();
navBar.PushNavigationItem (new UINavigationItem("Choose Location"), false);
navBar.BarStyle = UIBarStyle.Black;
navBar.Frame = new RectangleF(0,0,this.View.Frame.Width,45);
navBar.TopItem.RightBarButtonItem = new UIBarButtonItem("Done",UIBarButtonItemStyle.Bordered, delegate {FlipController.Flip();});
tableView = new UITableView()
{
Delegate = new TableViewDelegate(this, _locations),
DataSource = new TableViewDataSource(this, _locations),
AutoresizingMask = UIViewAutoresizing.FlexibleHeight|
UIViewAutoresizing.FlexibleWidth,
Frame = new RectangleF (0, 45, this.View.Frame.Width, this.View.Frame.Height-44)
, TableHeaderView = navBar
};
// Set the table view to fit the width of the app.
tableView.SizeToFit();
// Reposition and resize the receiver
tableView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height);
// Add the table view as a subview
this.View.AddSubview(tableView);
/*
Console.WriteLine("make flip button");
var flipButton = UIButton.FromType(UIButtonType.InfoDark);
flipButton.Frame = new RectangleF(290,10,20,20);
flipButton.Title (UIControlState.Normal);
flipButton.TouchDown += delegate {
FlipController.Flip();
};
Console.WriteLine("flipbutton created");
this.View.AddSubview(flipButton);
*/
}
private class TableViewDelegate : UITableViewDelegate
{
private MapLocationViewController _dvc;
private List<MapLocation> _locations;
public TableViewDelegate(MapLocationViewController controller, List<MapLocation> locations)
{
_dvc = controller;
_locations = locations;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
var loc = _locations[indexPath.Row];
Console.WriteLine("RowSelected: Label=" + loc.Title);
_dvc.FlipController.Flip(_locations[indexPath.Row].Location);
}
}
private class TableViewDataSource : UITableViewDataSource
{
static NSString kCellIdentifier = new NSString ("MyLocationIdentifier");
private MapLocationViewController _dvc;
private List<MapLocation> _locations;
public TableViewDataSource (MapLocationViewController controller, List<MapLocation> dates)
{
_dvc = controller;
_locations = dates;
}
public override int RowsInSection (UITableView tableview, int section)
{
return _locations.Count;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (kCellIdentifier);
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Default, kCellIdentifier);
}
cell.TextLabel.Text = _locations[indexPath.Row].Title;
cell.Accessory = UITableViewCellAccessory.None;
return cell;
}
}
}
}