-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTaskyViewController.fs
More file actions
61 lines (47 loc) · 2.08 KB
/
TaskyViewController.fs
File metadata and controls
61 lines (47 loc) · 2.08 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
namespace Tasky
open MonoTouch.UIKit
open MonoTouch.Foundation
open System
open System.Collections.Generic
open System.IO
open Data
type TaskDataSource(tasksource: task list, navigation: UINavigationController) =
inherit UITableViewSource()
let tasks = ResizeArray(tasksource)
let cellIdentifier = "TaskCell"
override x.RowsInSection(view, section) = tasks.Count
override x.GetCell(view, indexPath) =
let t = tasks.[indexPath.Item]
let cell =
match view.DequeueReusableCell cellIdentifier with
| null -> new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier)
| cell -> cell
cell.TextLabel.Text <- t.Description
cell
override x.RowSelected (tableView, indexPath) =
tableView.DeselectRow (indexPath, false)
navigation.PushViewController (new AddTaskViewController(tasks.[indexPath.Item], false), true)
override x.CanEditRow (view, indexPath) = true
override x.CommitEditingStyle(view, editingStyle, indexPath) =
match editingStyle with
| UITableViewCellEditingStyle.Delete ->
Data.DeleteTask tasks.[indexPath.Item].Id
tasks.RemoveAt(indexPath.Item)
view.DeleteRows([|indexPath|], UITableViewRowAnimation.Fade)
| _ -> Console.WriteLine "CommitEditingStyle:None called"
type TaskyViewController () =
inherit UIViewController ()
let table = new UITableView()
override this.ViewDidLoad () =
base.ViewDidLoad ()
let addNewTask =
EventHandler(fun sender eventargs ->
this.NavigationController.PushViewController (new AddTaskViewController(), true))
let button = new UIBarButtonItem(UIBarButtonSystemItem.Add, addNewTask)
this.NavigationItem.SetRightBarButtonItem (button, false)
table.Frame <- this.View.Bounds
this.View.Add table
override this.ViewWillAppear animated =
base.ViewWillAppear animated
table.Source <- new TaskDataSource(Data.GetIncompleteTasks(), this.NavigationController)
table.ReloadData()