Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            tableView.Source = new TableSource();
            tableSource      = (TableSource)tableView.Source;

            dbHelper.CreateDB();
            tableSource.taskList = dbHelper.getAllTasks();

            UIBarButtonItem buttonAdd = new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) =>
            {
                CreateAlertDialog(tableSource);
            });

            UIBarButtonItem buttonDeleteAll = new UIBarButtonItem(UIBarButtonSystemItem.Trash, (object sender, EventArgs args) =>
            {
                dbHelper.deleteAllTasks();
                tableSource.taskList.Clear();
                tableView.ReloadData();
            });

            UIBarButtonItem[] buttons = new UIBarButtonItem[] { buttonAdd, buttonDeleteAll };
            NavigationItem.SetRightBarButtonItems(buttons, false);

            UILongPressGestureRecognizer longPressGestureRecognizer = new UILongPressGestureRecognizer(LongPress);

            tableView.AddGestureRecognizer(longPressGestureRecognizer);

            UISwipeGestureRecognizer leftSwipeGesture = new UISwipeGestureRecognizer(SwipeLefttoRight)
            {
                Direction = UISwipeGestureRecognizerDirection.Right
            };

            tableView.AddGestureRecognizer(leftSwipeGesture);
        }
Exemplo n.º 2
0
        private void CreateAlertDialog(TableSource tableSource)
        {
            UIAlertView alert = new UIAlertView();

            alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
            alert.Title          = "Neuen Task anlegen";
            alert.AddButton("Abbrechen");
            alert.AddButton("OK");
            alert.Show();
            alert.Clicked += (sender, args) =>
            {
                if (args.ButtonIndex == 1)
                {
                    var newTask = new Task();
                    newTask.Name       = alert.GetTextField(0).Text;
                    newTask.IsDone     = false;
                    newTask.CreateDate = DateTime.Now;
                    tableSource.taskList.Add(newTask);
                    tableView.ReloadData();

                    dbHelper.addTask(newTask);
                }
            };
        }