forked from xamarin/ios-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert.cs
202 lines (167 loc) · 5.09 KB
/
alert.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//
// Alerts sample in C#
//
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;
public partial class AlertsViewController : UITableViewController {
// Load our definition from the NIB file
public AlertsViewController () : base ("AlertsViewController", null)
{
}
struct AlertSample {
public string Title, Label, Source;
public AlertSample (string t, string l, string s)
{
Title = t;
Label = l;
Source = s;
}
}
static AlertSample [] samples;
static AlertsViewController ()
{
samples = new AlertSample [] {
new AlertSample ("UIActionSheet", "Show simple", "alert.cs: DialogSimpleAction ()"),
new AlertSample ("UIActionSheet", "Show OK Cancel", "alert.cs: DialogOkCancelAction ()"),
new AlertSample ("UIActionSheet", "Show Customized", "alert.cs: DialogOtherAction ()"),
new AlertSample ("UIAlertView", "Show simple", "alert.cs: AlertSimpleAction ()"),
new AlertSample ("UIAlertView", "Show OK Cancel", "alert.cs: AlertOkCancelAction ()"),
new AlertSample ("UIAlertView", "Show Customized ", "alert.cs: AlertOtherAction ()"),
};
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Title = "Alerts";
TableView.DataSource = new DataSource ();
TableView.Delegate = new TableDelegate (this);
}
void DialogSimpleAction ()
{
var actionSheet = new UIActionSheet ("UIActionSheet <title>", null, null, "OK", null){
Style = UIActionSheetStyle.Default
};
actionSheet.Clicked += delegate (object sender, UIButtonEventArgs args){
Console.WriteLine ("Clicked on item {0}", args.ButtonIndex);
};
actionSheet.ShowInView (View);
}
void DialogOkCancelAction ()
{
var actionSheet = new UIActionSheet ("UIActionSheet <title>", null, "Cancel", "OK", null){
Style = UIActionSheetStyle.Default
};
actionSheet.Clicked += delegate (object sender, UIButtonEventArgs args){
Console.WriteLine ("Clicked on item {0}", args.ButtonIndex);
};
actionSheet.ShowInView (View);
}
void DialogOtherAction ()
{
var actionSheet = new UIActionSheet ("UIActionSheet <title>", null, "Cancel", "OK", "Other1"){
Style = UIActionSheetStyle.Default
};
actionSheet.Clicked += delegate (object sender, UIButtonEventArgs args){
Console.WriteLine ("Clicked on item {0}", args.ButtonIndex);
};
actionSheet.ShowInView (View);
}
void AlertSimpleAction ()
{
using (var alert = new UIAlertView ("UIAlertView", "<Alert Message>", null, "OK", null))
alert.Show ();
}
void AlertOkCancelAction ()
{
using (var alert = new UIAlertView ("UIAlertView", "<Alert Message>", null, "Cancel", "OK"))
alert.Show ();
}
void AlertOtherAction ()
{
using (var alert = new UIAlertView ("UIAlertView", "<Alert Message>", null, "Cancel", "Button1", "Button2"))
alert.Show ();
}
#region Delegates for the table
class DataSource : UITableViewDataSource {
static NSString kDisplayCell_ID = new NSString ("AlertCellID");
static NSString kSourceCell_ID = new NSString ("SourceCellID");
public override int NumberOfSections (UITableView tableView)
{
return samples.Length;
}
public override string TitleForHeader (UITableView tableView, int section)
{
return samples [section].Title;
}
public override int RowsInSection (UITableView tableView, int section)
{
return 2;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell;
if (indexPath.Row == 0){
cell = tableView.DequeueReusableCell (kDisplayCell_ID);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, kDisplayCell_ID);
cell.TextLabel.Text = samples [indexPath.Section].Label;
} else {
cell = tableView.DequeueReusableCell (kSourceCell_ID);
if (cell == null){
cell = new UITableViewCell (UITableViewCellStyle.Default, kSourceCell_ID){
SelectionStyle = UITableViewCellSelectionStyle.None
};
var label = cell.TextLabel;
label.Opaque = false;
label.TextAlignment = UITextAlignment.Center;
label.TextColor = UIColor.Gray;
label.Lines = 2;
label.Font = UIFont.SystemFontOfSize (12f);
}
cell.TextLabel.Text = samples [indexPath.Section].Source;
}
return cell;
}
}
class TableDelegate : UITableViewDelegate {
AlertsViewController avc;
public TableDelegate (AlertsViewController avc)
{
this.avc = avc;
}
public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
{
return indexPath.Row == 0 ? 50f : 22f;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
// deselect current row
tableView.DeselectRow (tableView.IndexPathForSelectedRow, true);
if (indexPath.Row == 0){
switch (indexPath.Section){
case 0:
avc.DialogSimpleAction ();
break;
case 1:
avc.DialogOkCancelAction ();
break;
case 2:
avc.DialogOtherAction ();
break;
case 3:
avc.AlertSimpleAction ();
break;
case 4:
avc.AlertOkCancelAction ();
break;
case 5:
avc.AlertOtherAction ();
break;
}
}
}
}
#endregion
}